JavaScript Array And Object Methods.pdf

JavaScritp-Arrays-and-Objects.pdf
Preview of JavaScript Array and Object Methods
🔗 Source: basescripts.com
📊 Size: 208 KB
📄 Pages: 29 pages
⬇️ Downloads: 60

Summary

Arrays:
- Creation: `const arr = ['Laurence', 4, 5, 5, 5, 6, 'Svekis'];` or `const arr1 = new Array('Laurence', 'Svekis');`
- Accessing Elements: `console.log(arr[1]);` or `console.log(arr1[0]);`
- Length: `console.log(arr.length);`
- Last Element: `console.log(arr[arr.length - 1]);`
- Nested Arrays: Loop through inner arrays using nested loops: `for (let x = 0; x < arr[i].length; x++) { console.log(arr[i][x]); }`
- Array Static Methods:
- `Array.from()`: Create an array from an array-like or iterable object. `const arr = Array.from(str);`
- `Array.of()`: Create a new array with specified elements. `const arr4 = Array.of(5);`
- `Array.isArray()`: Check if an object is an array. `console.log(Array.isArray(arr));`
- Array Update Methods:
- `arr.push(...)`: Add elements to the end of an array. `arr.push(10);`
- `arr.pop()`: Remove and return the last element of an array. `const popped = arr.pop();`
- `arr.shift()`: Remove and return the first element of an array. `const shifted = arr.shift();`
- `arr.unshift(...)`: Add elements to the beginning of an array. `arr.unshift(1, 2);`
- `arr.splice(index, deleteCount, ...items)`: Change content by removing or replacing existing elements and/or adding new elements in place. `arr.splice(2, 2, 'new', 'element');`
- Array Filter Methods:
- `arr.filter(callback)`: Create a new array with all elements that pass the test implemented by the provided function. `const filtered = arr.filter(ele => ele > 5);`
- `arr.includes(searchElement, fromIndex)`: Determine whether an array includes a certain value among its entries, returning `true` if it does, `false` otherwise. `console.log(arr.includes(5));`
- Array Map Method: Create a new array with the results of calling a provided function on every element in the calling array. `const mapped = arr.map(ele => ele * 2);`
- Array Reduce Method: Execute a reducer function (that you provide) on each element of the array, resulting in a single output value. `const sum = arr.reduce((acc, ele) => acc + ele, 0);`
- Array Sort Method: Sort the elements of an array in place and returns the array. `arr.sort((a, b) => b - a);`
- Array Iteration: Use `for...of` loop to iterate over array elements. `for (const ele of arr) { console.log(ele); }`

Objects:
- Creation: `const obj = { first: 'Laurence', last: 'Svekis' };` or `const obj1 = new Object(); obj1.first = 'Laurence'; obj1.last = 'Svekis';`
- Object Static Methods:
- `Object.assign(target, ...sources)`: Copies the values of all enumerable own properties from one or more source objects to a target object. `const obj2 = Object.assign({}, obj, { middle: 'S' });`
- `Object.keys(obj)`: Returns an array of a given object's own enumerable string-keyed property names. `console.log(Object.keys(obj));`
- `Object.values(obj)`: Returns an array of a given object's own enumerable value-keyed property values. `console.log(Object.values(obj));`
- `Object.entries(obj)`: Returns an array of a given object's own enumerable string-keyed property [key, value] pairs. `console.log(Object.entries(obj));`
- Object Iteration: Use `for...in` loop to iterate over object properties. `for (const prop in obj) { console.log(`${prop}: ${obj[prop]}`); }`
- Object Cloning: Use `Object.assign()` or spread operator (`{ ...obj }`) to create a shallow copy of an object. `const clone = { ...obj };`
- Object Deep Cloning: Use `JSON.parse(JSON.stringify(obj))` to create a deep copy of an object. `const deepClone = JSON.parse(JSON.stringify(obj));`

Description

Create, access nested values, use static methods, clone, loop items, update, filter, map, and get unique values.
- **Objects**: Create, use static methods, loop values, and check for key existence.

Technical Information

  • File Format: PDF
  • File Size: 208 KB
  • Pages: 29
  • Language: EN
  • Total Downloads: 60
  • Last Updated: 2 weeks ago

Document Overview

This PDF document about JavaScript Array and Object Methods provides comprehensive information and guidance. Whether you're a beginner or advanced user, this resource offers valuable insights into JavaScript Array and Object Methods.

Related Topics

If you're interested in JavaScript Array and Object Methods, you might also want to explore:

Download JavaScript Array and Object Methods eBooks for free and learn more about JavaScript Array and Object Methods. These books contain exercises and tutorials to improve your practical skills, at all levels!

Not satisfied with this document? We have related documents to JavaScript Array and Object Methods, try searching with similar keywords: JavaScript Array and Object Methods, Javascript Object Into Object, PDF JavaScript Introduction To Object Oriented JavaScript, Array Methods Javascript, Array And Phased Array Antenna Basics, Array Definition Of Array By The Free Dictionary, Phased Array Inspections Phased Array, Jquery Convert Object To Array

You can download PDF versions of the user's guide, manuals and ebooks about JavaScript Array and Object Methods, you can also find and download for free A free online manual (notices) with beginner and intermediate, Downloads Documentation, You can download PDF files (or DOC and PPT) about JavaScript Array and Object Methods for free, but please respect copyrighted ebooks.