a
a
aizatto.com
Build.my
GitHub
Linkedin
Notion
Search…
aizatto.com
Table of Contents
Portfolio, Projects, Tools, Toys
Interview Guide
Engineering Code
Engineering Management
Why GitBook?
Getting into Tech
Personal Goals
Daily Drivers
Contacting Me
Notes
AWS
JavaScript
Array
Async & Await / Promises
Booleans
Collections
Cons/Dislikes
fetch
Map
Modules
Object
Regex
Set
Style Guides
Versions
Node.js
Software Engineering
Technical Due Diligence
Web Development
Archive
More on Notion
Powered By
GitBook
Array
​
MDN
​
Test Array
1
Array
.
isArray
(
array
)
Copied!
This does not work to test if its an array.
1
if
(
array
)
{
2
// empty arrays evaluate as false
3
}
4
​
5
if
(
array
&&
array
.
length
>
0
)
{
6
// you may still want to capture the array
7
}
Copied!
Clone an array
1
const
clone
=
array
.
slice
(
0
);
Copied!
Iterate keys in an array
(for...in)
1
const
array
=
[
'x'
,
'y'
,
'z'
];
2
for
(
const
key
in
array
)
{
3
console
.
log
(
key
);
4
}
Copied!
1
0
2
1
3
2
Copied!
​
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in
​
Iterate values in an array
(for...of)
1
const
array
=
[
'x'
,
'y'
,
'z'
];
2
for
(
const
value
of
array
)
{
3
console
.
log
(
value
);
4
}
Copied!
1
x
2
y
3
z
Copied!
​
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
​
Appending/merging arrays together
Reuse Array:
1
array1
.
push
(
...
array2
);
Copied!
New Array:
1
const
array3
=
array1
.
concat
(
array2
);
Copied!
Notes - Previous
JavaScript
Next
Async & Await / Promises
Last modified
3yr ago
Copy link
Contents
Test Array
Clone an array
Iterate keys in an array (for...in)
Iterate values in an array (for...of)
Appending/merging arrays together