All Questions
Tagged with object ecmascript-6
65
questions
167
votes
2
answers
101k
views
Destructuring and rename property
const a = {
b: {
c: 'Hi!'
}
};
const { b: { c } } = a;
Is it possible rename b in this case? I want get c and also rename b.
29
votes
2
answers
5k
views
What is an "internal slot" of an object in JavaScript?
I've tried to understand ECMAScript 2015 specification in one point: Internal Slots of Objects. But this section appeared very unclear to me, especially this sentence:
Internal slots correspond to ...
11
votes
5
answers
7k
views
ES6 destructuring object assignment function parameter default value
Hi I was going through examples of object destructuring use in passing function parameters here Object Destructuring Demo
function drawES6Chart({size = 'big', cords = { x: 0, y: 0 }, radius = 25} = ...
86
votes
10
answers
121k
views
How to create a derived class in JavaScript?
I have a base class:
function Monster() {
this.health = 100;
}
Monster.prototype.growl = function() {
console.log("Grr!");
}
That I want to extend and create another class with:
function ...
16
votes
11
answers
36k
views
Find all values by specific key in a deep nested object
How would I find all values by specific key in a deep nested object?
For example, if I have an object like this:
const myObj = {
id: 1,
children: [
{
id: 2,
children: [
{
...
119
votes
4
answers
67k
views
Succinct/concise syntax for 'optional' object keys in ES6/ES7? [duplicate]
There are already a lot of cool features in ES6/ES7 for defining Javascript objects. However, the following pattern is common in Javascript:
const obj = {
requiredKey1: ...,
requiredKey2: ...
}...
24
votes
9
answers
51k
views
How to filter an object by its values in ES6
What is the best way to filter an object this way in ES6?
Starting data:
const acceptedValues = ["value1", "value3"]
const myObject = {
prop1: "value1",
prop2: &...
4
votes
5
answers
23k
views
How to convert key-value pair object into an array of values in ES6?
I'm developing a React application where I need to convert a key-value object like this:
{
0: 'John',
1: 'Tim',
2: 'Matt'
};
To an array of just the values like this:
['John', 'Tim', 'Matt']
...
14
votes
2
answers
20k
views
Remove key from all objects in array
I have the following array of objects:
[{id:1, value:"100", name:"dog" ...},
{id:2, value:"200", name:"cat" ...},
{id:3, value:"300", name:"fish"....},
{id:4, value:"400", name:"mouse" ...},
{id:5, ...
14
votes
4
answers
11k
views
How to destructure nested object with null value using default value
When trying to destructure a nested object which could be null, the default value is not being used.
I have accomplished this by destructuring in multiple stages, but would rather do it in a single ...
7
votes
2
answers
301
views
MDN "Object.is" alternative proposal
I have read the MDN page on the "Object.is" method.
It gives an alternative code for the browsers that do not provide this method:
if (!Object.is) {
Object.is = function(v1, v2) {
if (v1 =...
118
votes
1
answer
62k
views
Destructuring nullable objects
Typescript (or should we say ES) doesn't allow destructuring of null/undefined objects. It throws TypeError.
So, lets say we have something like
let {a,b,c} = D;
where D could be null.
If we need ...
39
votes
5
answers
35k
views
What is a good way to automatically bind JS class methods?
I get tired of writing code like this:
class Something {
constructor() {
this.method = this.method.bind(this);
this.anotherOne = this.anotherOne.bind(this);
// ...
}
...
21
votes
5
answers
10k
views
ES6 Classes - Updating Static Properties
I am trying to figure out alternative ways to set a static (or class) property an ES6 Class and then change it after new instances of the class are created.
For example, lets say I have a class ...
12
votes
6
answers
23k
views
Find and replace object in array (based on id)
Got a bit of a puzzle here...I want to loop through allItems and return allItems but replace with any newItems that matches its id. How can I look for a match on id and then replace it with the ...