Animations

API

Arrays

Async

Basics

Challenges

Classes

Console

Dates

Debugging

DOM Elements

DOM Methods

DOM Navigation

DOM Properties

Event Listeners

Flow Control

Forms

Functions

Global Functions

JSON

Keywords

Libraries (3rd party)

Math

Modules

Objects

Snippets

String

Types

Widgets

Window Object

JavaScript - spread

https://www.w3schools.com/jsref/jsref_obj_array.asp

You can take a js object and spread it by using a special ... three-dot syntax. This will take all of the object's properties and place them into an array. This might be easier to implement - especially when passing items to a function with a lot of arguments.

Technically speaking, spread is a new ECM6 operator and not a array method. However, since it's mostly used with arrays, I have placed it here.


let person = { Name: "Ricky Bobby", Occupation: "Race Car Driver", Gender: "Male", Age: 45 };

// take person and create an array called rickyBobby
let { ...rickyBobby } = person;


// for UI. Method wants an array.
const DisplayPersonData = (person) =>
{
    $("#spread-demo").html(`Name: ${person["Name"]}<br />Occupation: ${person["Occupation"]}`)
};

DisplayPersonData(rickyBobby);

results: