-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray-functions.js
More file actions
37 lines (25 loc) · 1.45 KB
/
Array-functions.js
File metadata and controls
37 lines (25 loc) · 1.45 KB
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
const arr1=["hello","world"]
const arr2=["good","morning"]
console.log(arr1.concat(arr2))
arr1.push(arr2) // push() append complete array into array
console.log(arr1)
const arr=arr1.concat(arr2) // concat() append all element into array
console.log(arr)
const another=[...arr1,...arr2] //spreading of array
console.log(another)
const dummy=[3,6,[4,0],1,[9,[8,7,[2,[5]]]]]
console.log(dummy.flat(Infinity))
// flat() will simply give all elements of the array avoiding nested array upto mentioned depth
// -> use "Infinity" if you want to flat entire array without certain depth
//--------------------------------------------------------------------------------------------------------------
console.log(Array.isArray("hello!!")) // print true/false parameter is array or not
console.log(Array.isArray(arr))
console.log(Array.from("GoodMorning")) // convert to array from entered parameter only if convertable
console.log(Array.from({name:"xyz",class:"IT"}))
// in above statement object is not convertable to array so it will return empty object
// if you want to make array from a object so you have to mention either key OR value to form Array
//-------------------------------------------------------------------------------------------------------------
let num1=1
let num2=2
let num3=3
console.log(Array.of(num1,num2,num3)) // Array.of() is used to form an array using input parameter