-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyArray.js
More file actions
34 lines (27 loc) · 990 Bytes
/
myArray.js
File metadata and controls
34 lines (27 loc) · 990 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
33
34
const oneArray=[1,2,3,4]
const twoArray=[5,6,7,8]
//const threeArray=oneArray.concat(twoArray)// add elements of both array to third array
//console.log(threeArray)
//if we do
//const threeArray=[oneArray,twoArray]
//console.log(threeArray)//prints alag alag array separated with comma
//Another method
//spread operator
const threeArray=[...oneArray,...twoArray]
console.log(threeArray)// prints the same result as concat
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//now to convert object into arrays
//
function manyArguments(){
let args=Array.from(arguments)//argumnets is a reserved iteratable object
finalArr=args.map(e=>e*2)//and Array.from() is a method to convert objects into array
console.log(finalArr)
}
manyArguments(1,2,3,4)
//Rest operator
function manyArgumentsv2(...args){
let finalArr=args.map(e=>e)
console.log(finalArr)
console.log(typeof args)// output will be object
}
manyArgumentsv2(1,2,3,4)