-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproble7.js
More file actions
32 lines (18 loc) · 715 Bytes
/
Copy pathproble7.js
File metadata and controls
32 lines (18 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* You are given an array:
var fruits = ['Apple', 'Banana', 'Orange'];
a) Find the index of ‘Banana’ and replace ‘Banana’ with ‘Mango’.
b) Remove ‘Orange’ and add ‘Watermelon’.
[View problem source 📤](https://drive.google.com/file/d/1bfxye7A1p-BBJCQCXaiUetl_qyS2Vc1E/view) */
var fruits = ['Apple', 'Banana', 'Orange'];
// Part (a) 1.index of ‘Banana’
var bananaIndex = fruits.indexOf("Banana");
console.log(bananaIndex);
// Part (a) 2. replace ‘Banana’ with ‘Mango’.
fruits[1]='Mango';
console.log(fruits);
// Part (b) 1. Removing ‘Orange’
fruits.pop()
console.log( fruits);
// Part (b) 2. Adding ‘Watermelon’
fruits.push("Watermelon");
console.log(fruits);