Clone Objects in JavaScript

object,tipjs

Clone Objects in JavaScript

const food = { beef: '🥩', bacon: '🥓' }

// "Spread"
{ ...food }

// "Object.assign"
Object.assign({}, food)

// "JSON"
JSON.parse(JSON.stringify(food))

// RESULT:
// { beef: '🥩', bacon: '🥓' }

Có thể bạn đã miss một số snippets code

Getting the last element of a split string array

Getting the last element of a split string array

Spread Operator for Objects

Using the spread operator during an Object declaration will assign the properties of the referenced Object to the new Object.

Using promises to catch errors

Convert Array-like to True Array

Convert Array-like to True Array

Object.fromEntries

Object.fromEntries Là một phương thức mới được giới thiệu trong ES10 được sử dụng để chuyển đổi từ list có dạng key và value thành những objects.