-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_array.js
More file actions
60 lines (38 loc) · 2.47 KB
/
10_array.js
File metadata and controls
60 lines (38 loc) · 2.47 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//************************************************************************************* */
const cd03 = [851, 8525, 556, 452, 8552, 852]
const cd04 = [1, 2, 3, 7, 8, 9, 5]
const cd05 = cd03.concat(cd04)
console.log(cd05)
/*Result - [851, 8525, 556, 452, 8552, 852, 1, 2, 3, 7, 8, 9, 5]*/
const cd06 = [...cd03, ...cd04] // this is sprade method
console.log(cd06)
/* Result - [851, 8525, 556, 452, 8552, 852, 1, 2, 3, 7, 8, 9, 5] */
// you have same result as a concat
//************************************************************************************* */
const array001 = [1, 2, 3, 8, 9, 8, [8, 7, 9, 2, 8, 5,], [8, 9 , 2, 5, 8, 3, 8, 7, [9, 3, 1, 2]]]
const array002 = array001.flat(Infinity) // useing flate method you can convert sub array to single array
const array003 = array001.flat(3) // useing flate method you can convert sub array to single array
console.log(array001)
/* Result : [ 1, 2, 3, 8, 9, 8, [ 8, 7, 9, 2, 8, 5 ], [ 8, 9, 2, 5, 8, 3, 8, 7, [ 9, 3, 1, 2 ] ]*/
console.log(array002)
/* Result : [ 1, 2, 3, 8, 9, 8, 8, 7, 9, 2, 8, 5, 8, 9, 2, 5, 8, 3, 8, 7, 9, 3, 1, 2 ] */
console.log(array003)
/* Result : [ 1, 2, 3, 8, 9, 8, 8, 7, 9, 2, 8, 5, 8, 9, 2, 5, 8, 3, 8, 7, 9, 3, 1, 2 ] */
//*************************************************************************************//
console.log(Array.isArray("Sujit Tomar")) // result - false (you can ask question this is array or not ?)
console.log(Array.isArray(cd03)) // result - true (you can ask question this is array or not ?)
//*************************************************************************************//
const myName = "Sujit Tomar" // with string can you convert in array?
const myNameArry = Array.from(myName)
console.log(myNameArry) // Result : ['S', 'u', 'j', 'i', 't', ' ', 'T', 'o','m', 'a', 'r' ]
/* so you can change string to array using Array.from method and remember in this method your string space area also convert in array and reserve index*/
const myNameArry01 = Array.from({name:myName}) // with object can you convert in array?
console.log(myNameArry01) // its provide blank array
/*So you can not change object to array with this method*/
//*************************************************************************************//
console.log("****************************** From Here *********************************")
const score01 = 100
const score02 = 200
const score03 = 500
const scoreArray = Array.of(score01, score02, score03)
console.log(scoreArray) // result [100, 200, 300]