JavaScript Backend Flashcards
Read a JSON file
fetch(‘path/to/JSON.json’)
.then(res => res.json())
.then(data => {
console.log(data);
})
.catch(err => console.error(‘Error’: err));
Add to end of array
arr.push(4)
Remove starting element from array
arr.shift()
Remove last element in array
arr.pop()
Remove element/s in middle of array
arr.splice(1, 2)
Add element/s to middle of array
arr.splice(1, 0, 2, 3) //adds 2, 3 at index 1
Convert string to array
arr.split(‘’)
Extract substring
str.slice(0, 5)
Convert string to upper case
str.toUpperCase()
Convert string to lower case
str.toLowerCase
Does string include value
str.includes(‘a’)
Does a certain key exist in object
obj.hasOwnProperty(‘a’)
‘a’ in obj
Add key value pair to object
obj[‘c’] = 3
Get array of keys from object
Object.keys(obj)
Delete key value pair
delete obj.a
Loop through keys in an object
for (let key in obj) {
}