Javascript Cheat Sheet
Javascript Cheat Sheet
JAVASCRIPT : BASICS II
// Arrays can hold a mix of data types
let numArray = [13, 36, 45, 57, 14];
let mixedArray = ["a", "b", 1, 2, 3];
const book = {
.length Property tells us the length of an array
title: "The Hobbit",
let fruits = ["apple", "banana", "orange"]; author: "J.R.R. Tolkien",
// Assign array length to a variable year: 1937
const numFruits = fruits.length; };
console.log(numFruits); // Output: 3
// Access a property
Array Methods Used for editing array elements
console.log(book.title);
// Adds element to end of array // Output: The Hobbit
fruits.push("pear");
// Assign a new property
// Adds element to beginning of array book.edition = "1st Edition";
fr
uits.unshift("strawberry");
console.log(book);
// Removes and returns the first element /* Output: {
fr
uits.shift(); title: "The Hobbit",
year: 1937,
// Removes and returns the last element author: 'J.R.R. Tolkien',
fr
uits.pop(); edition: '1st Edition'} */
Made with by