-
Notifications
You must be signed in to change notification settings - Fork 23
/
properties_and_methods_of_arrays.js
86 lines (38 loc) · 1.43 KB
/
properties_and_methods_of_arrays.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Some properties and methods of array are :
// 1. Returns the number of elements :
//length
// example
var fruits = ["Orange", "Apple", "Banana"];
console.log(fruits.length);
// Output : 3
// 2. Sorts the array :
//sort();
// example
var fruits = ["Orange", "Apple", "Banana"];
console.log(fruits.sort());
// Output : ['Apple', 'Banana', 'Orange']
// 3. Joins arrays and returns an array with the joined arrays :
//concat();
// example
var fruits = ["Orange", "Apple", "Banana"];
var car = ["Audi", "BMW", "Ferrari"];
console.log(fruits.concat(car));
// Output : [ 'Orange', 'Apple', 'Banana', 'Audi', 'BMW', 'Ferrari' ]
// 4. Joins all elements of an array into a string :
//join();
// example
var fruits = ["Orange", "Apple", "Banana"];
console.log(fruits.join());
// Output : Orange,Apple,Banana
// 5. Search the array for an element and returns its position :
//indexOf();
// example
var fruits = ["Orange", "Apple", "Banana"];
console.log(fruits.indexOf("Apple"));
// Output : 1
/*
------------------------------------------------------------------------------------
Challenge 1: Find the length of the array Car ["Audi", "BMW", "Ferrari"] using the properties of the array.
Challenge 2: Find the postition of the element "BMW" in the array Car ["Audi", "BMW", "Ferrari"] using the properties of the array.
------------------------------------------------------------------------------------
*/