Section 17
3308 ワード
Udemy Web Developer Bootcamp Section 17
JavaScript Arrays
JS Arrays are a data structure.
A data structure simply is a collection of data(boolean value, strings).
A data structures, specifically arrays which we're about to see, allow us to group data together ans we could store different strings.
let students = [];
let colors = ["red", "orange", "yellow"];
Modifying Arrays
Unlike with the string, it is possible to change particular characters in an array.
Array Methods
array.push('item')
Add to endString remains unchanged, but with arrays when I
push
onto array, array actually is updated and what it returns is the technical term is the new length of the array. array.pop()
remove from end array.shift()
Remove from start array.unshift('item')
Add to start - concat : merge arrays
array1.concat(array2)
- includes : look for a value array.includes('item')
- indexOf : just like string.indexOf array.indexOf('index')
- join : creates a string from an array- reverse : reverses an array
array.reverse()
- slice : copies a portion on an array array.slice(start, end)
- splice : removes/replaces elements array.splice(start, deleteCount, 'item')
- sort : sorts an array array.sort()
Reference Types & Equality Testing
JS actually doesn't care about what's inside, at least with arrays.
So when I make a new array ans it has its own address, its own reference, its own social security number.
Even if the contents are the same, they are distinct because the social security numbers are different.
They are the same exact reference. But it's not going to help us if we're trying to compare the contents.
Const & Array
But as soon as I try and set arrays to something entirely defferent, a new reference, we get an error.
Multi-Dimensional Arrays
Reference
この問題について(Section 17), 我々は、より多くの情報をここで見つけました https://velog.io/@awesomee/Section-17テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol