-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharray.js
More file actions
29 lines (23 loc) · 917 Bytes
/
Copy patharray.js
File metadata and controls
29 lines (23 loc) · 917 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
let arr = [1, 'arvind', [1, 2], { name: 'anurag', age: 21 }, (a, b) => a + b];
console.log(arr[0]);
console.log(arr[2]);
console.log(arr[0].length);
console.log(typeof arr[2]); // can't be sure if array
console.log(Array.isArray(arr[2])) // correct way to check if array
if (typeof arr[3] === 'object') {
if (arr[3].hasOwnProperty('name')) {
console.log(arr[3].name);
}
}
if (typeof arr[4] === 'function') {
console.log(arr[4](2, 3));
}
arr = ["b", "c", "d"];
console.log(arr.push("e"), arr); // returns 4; arr is now ["b", "c", "d", "e"]
arr.pop(); // returns "e"; arr is now ["b", "c", "d"]
arr.unshift("a"); // returns 4; arr is now ["a", "b", "c", "d"]
arr.shift(); // returns "a"; arr is now ["b", "c", "d"]
const cart = [ { name: "Widget", price: 9.95 }, { name: "Gadget", price: 22.95 }];
const names = cart.map(x => x.name);
const lnames = names.map(String.toLowerCase);
console.log(lnames)