Skip to content

Latest commit

 

History

History
15 lines (11 loc) · 513 Bytes

add-attribute-to-json-object-using-spread-operator.md

File metadata and controls

15 lines (11 loc) · 513 Bytes

Add an attribute to a json object using spread operator

The Spread Operator is "..." three dots, which allows to extend an object.

Code for adding attributes to an existing json object:

var parts = ['shoulders', 'knees'];
var lyrics = ['head', ...parts, 'and', 'toes']; // ["head", "shoulders", "knees", "and", "toes"]

You can also extend the same object also:

parts =  [...parts, 'and', 'toes'];