let original = {name: 'Joel', favoriteFood: 'oranges', age: 26};
let happyBirthday = {...original, age: 27};

happyBirthday will be an object that is identical to original but with the age overwritten.

So that would result in an object like this:

{name: 'Joel', favoriteFood: 'oranges', age: 27} // Notice the age
Answer from Pedro Filipe on Stack Overflow
🌐
Reddit
reddit.com › r/javascript › conditionally spreading objects in javascript
r/javascript on Reddit: Conditionally spreading objects in JavaScript
September 19, 2022 - Using the spread operator on a boolean but having it operate on the object just seems really wrong. You're not using the spread on a boolean, though. Due to operator precedence, it's ...(cond1 && obj1). And since in JavaScript, logical operators don't return boolean values, but one of their operands, cond1 && obj1 will return obj1 if cond1 is a truthy value, and thus the spread operator will be applied obj1.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Spread_syntax
Spread syntax (...) - JavaScript | MDN
The spread (...) syntax allows ... array literals) are expected. In an object literal, the spread syntax enumerates the properties of an object and adds the key-value pairs to the object being created....
Discussions

Spread Operator(Object inside Object)
const user= { name: "Diego", age: 23, address: { city: "Toronto", country: "Canada", phone: "9119119111" } }; I’m trying to use the spread operator to change only the city property of the address Object If I try const user2 = {...user, address: { city: "Quebec"}}; I’m gonna lose the other ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
October 8, 2019
javascript - Quick question about ES6 spread operator on objects - Stack Overflow
I just have a brief question about using spread operators on objects, when we are trying to return a copy of the object with a field changed. I've been working through a PluralSight tutorial having... More on stackoverflow.com
🌐 stackoverflow.com
Adding arbitrary attributes to object using spread operator
It’s not really a bug. If they performed excess property checks with spreading, the resulting errors would be very awkward to work around. Generally, typescript doesn’t care about excess properties. This is why Object.keys emits strings and not keyof T. More on reddit.com
🌐 r/typescript
4
2
April 25, 2024
Spread-object operator missing in kotlin? - Language Design - Kotlin Discussions
I was wondering if there is something like the spread-object operator found in Javascript/Typescript? I am aware that there is a spread function arguments operator. The spread object operator allows one to pass-on attribute values of objects of shared types without constructors. More on discuss.kotlinlang.org
🌐 discuss.kotlinlang.org
1
June 1, 2018
🌐
Esdiscuss
esdiscuss.org › topic › spread-and-non-objects
Spread and non objects
It would seem friendlier for the spread operator to treat it them as a empty array otherwise you end up with code like: ... Yeah, null testing is a drag. People skipt it (I hear this about regexp exec -- it should return an empty array on mismatch -- counter-argument is that empty arrays are truthy). The dual of spread-as-operator is spread-as-rest-arg-syntax.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Spread Operator(Object inside Object) - JavaScript - The freeCodeCamp Forum
October 8, 2019 - const user= { name: "Diego", age: 23, address: { city: "Toronto", country: "Canada", phone: "9119119111" } }; I’m trying to use the spread operator to change only the city property of the address Object If I try const user2 = {...user, address: { city: "Quebec"}}; I’m gonna lose the other ...
🌐
W3Schools
w3schools.com › react › react_es6_spread.asp
React ES6 Spread Operator
The JavaScript spread operator (...) allows us to quickly copy all or part of an existing array or object into another array or object.
🌐
Appsmith
community.appsmith.com › content › guide › javascript-spread-operator-what-are-those-three-dots-my-code
The Javascript Spread Operator - What Are Those Three Dots in My Code? | Appsmith Community Portal
August 29, 2023 - This seemingly simple syntax holds incredible potential, transforming the way we approach various coding scenarios. To spread the elements of one array into another, you simply use the spread operator followed by the array you want to spread.
Find elsewhere
🌐
Dillion's Blog
dillionmegida.com › p › spread-operator-simplified
Spread Operator in JavaScript, Simplified - Dillion's Blog
November 22, 2022 - console.log(fullInfo) // { // name: 'Micheal', // age: 100, // language: 'JavaScript', // stack: 'frontend' // } In this example, the name property of fullInfo comes after the spread info object, so the name of fulInfo would overwrite the name coming from the info object. The spread operator can also be used to spread arrays as function arguments.
🌐
Reddit
reddit.com › r/typescript › adding arbitrary attributes to object using spread operator
r/typescript on Reddit: Adding arbitrary attributes to object using spread operator
April 25, 2024 -

Why is it possible to add arbitrary attributes to an object? This should throw a Typescript error in my opinion.

type Params = {
    limit: number;
}

// Does not work
const params: Params = {
    limit: 20,
    q: "john"
}

// Does work
const spreadParams: Params = {
    limit: 20,
    ...({ q: "john" })
};

console.log(spreadParams.q);
// 'john'

https://www.typescriptlang.org/play/?ssl=18&ssc=10&pln=1&pc=1#code/C4TwDgpgBACghgJzgWwM5QLxQN4CgoFQA2AlsicAFxQB2ArsgEYQIDcuAvrrgPQ9QARAPYR0NIcCgB3IQgDWuAMZCaqSWEQpU1eEjSYc+QqXJUoAJgAMAGiMEAjtQBEAKyEALGk87c+gkegy8koqalCoYAgQcAAmulo6mvpYeITEZBTUVrZpAHT5ABTYUI5Qrh5eUBwAlJzsIapCRBC5REIA5gURUbHxaLn21ex+AORuniO4QA

🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-spread-operator
JavaScript Spread Operator - GeeksforGeeks
The Spread operator (represented as three dots or …) is used on iterables like array and string, or properties of Objects, to expand wherever zero or more elements are required to be copied or assigned.
Published   July 11, 2025
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › advanced working with functions
Rest parameters and spread syntax
October 18, 2022 - Object.assign(dest, src1, ..., srcN) – copies properties from src1..N into dest.
🌐
Kotlin Discussions
discuss.kotlinlang.org › language design
Spread-object operator missing in kotlin? - Language Design - Kotlin Discussions
June 1, 2018 - I was wondering if there is something ... arguments operator. The spread object operator allows one to pass-on attribute values of objects of shared types without constructors....
🌐
DEV Community
dev.to › marinamosti › understanding-the-spread-operator-in-javascript-485j
Understanding the Spread Operator in JavaScript - DEV Community
September 23, 2019 - Spread syntax allows an iterable ... array literals) are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected....
🌐
Medium
cleverzone.medium.com › demystifying-javascript-spread-operat-71924c888a8
Demystifying JavaScript : Spread operator (…) | by Cleverzone | Medium
August 26, 2023 - The spread operator, denoted by three dots (...), allows JavaScript developers to easily split array elements or object properties and spread them into a new array or object. This operator is aptly named "spread" because it enables us to spread ...
🌐
SitePoint
sitepoint.com › blog › javascript › quick tip: how to use the spread operator in javascript
Quick Tip: How to Use the Spread Operator in JavaScript — SitePoint
November 7, 2024 - The JavaScript spread operator, symbolized by three dots (…), was introduced in ES6 and can be used to expand elements in collections and arrays into single, individual elements.
🌐
Medium
medium.com › @slamflipstrom › conditional-object-properties-using-spread-in-javascript-714e0a12f496
Conditional Object Properties Using Spread in JavaScript | by Sam Lindstrom | Medium
June 6, 2019 - The && will then ignore the inner object, and a false value will be the remaining value to be spread into updateUserObj. The reduced form of line 2 is now ...(false). This all looked strange to me at first, but what’s clever about this is the fact that nothing is returned and subsequently applied from spread here. The line 2 expression omits a name from being applied if the condition fails. This works because the spread operator ignores values without a property, so age and hairColor are the only properties applied to updateUserObj.
🌐
W3Schools
w3schools.com › howto › howto_js_spread_operator.asp
How To Use the Spread Operator (...) in JavaScript
The JavaScript spread operator (...) expands an iterable (like an array) into more elements.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Destructuring
Destructuring - JavaScript | MDN
The object and array literal expressions provide an easy way to create ad hoc packages of data. ... The destructuring uses similar syntax but uses it on the left-hand side of the assignment instead. It performs the reverse operation of an array declaration, by declaring each element in the ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-spread-operator
What's the Spread Operator Used For in JavaScript? | DigitalOcean
July 11, 2022 - The spread operator is a feature of JavaScript introduced with ES6 that gives you access to the insides of an iterable object. An “iterable object” is anything you can iterate over item by item, such as arrays, objects literals, and strings. These kinds of JavaScript types can be traversed ...
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript object spread
JavaScript Object Spread Operator (...)
November 4, 2024 - TypeError: Cannot assign to read only property 'color' of object '#<Object>'Code language: JavaScript (javascript) Object spread operator (...) unpacks the own enumerable properties of an object.