Skip to main content

All Questions

Tagged with
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.
leusrox's user avatar
  • 2,225
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: ... }...
Andrew Mao's user avatar
  • 36.5k
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 ...
tlzg's user avatar
  • 14.7k
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 ...
Lucas Penney's user avatar
  • 2,664
46 votes
8 answers
53k views

jest .each name access object key

Is it possible to access an object's key inside the name portion of a .each? let accounts = [ { details: { company_name: "...
A. L's user avatar
  • 12.4k
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); // ... } ...
Dominic P's user avatar
  • 2,334
39 votes
1 answer
19k views

Can I use continue and break in Javascript for...in and for...of loops?

Can I use the break and continue statements inside the for...in and for...of type of loops? Or are they only accessible inside regular for loops. Example: myObject = { propA: 'foo', propB: '...
cbdeveloper's user avatar
  • 30.4k
38 votes
5 answers
13k views

Difference between Configurable and Writable attributes of an Object

I saw the following regarding javascript, object data property attributes — 
Configurable: Specifies whether the property can be deleted or changed. — Enumerable: Specifies whether the property can ...
Bravo's user avatar
  • 8,979
35 votes
12 answers
106k views

Select a property from an array of objects based on a value : Javascript

I have an array of objects with the following structure: var arr = [ { "value": "abc", "checked": true }, { "value": "xyz", "checked": false }, { "value": "...
joy08's user avatar
  • 9,512
35 votes
6 answers
30k views

Object.keys using numbers in typescript

type Foo = { [key: number]: string } const foo: Foo = { 100: 'foo', 200: 'bar' } const sizes: number[] = Object.keys(foo) Gives me: Type 'string[]' is not assignable to type 'number[] Why does ...
David Hellsing's user avatar
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 ...
BairDev's user avatar
  • 3,095
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: &...
saawsann's user avatar
  • 675
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 ...
Jared's user avatar
  • 651
19 votes
11 answers
431 views

How to rename object keys inside array

I have an array of objects like this: const customers = [ { customer_name: 'Negan', customer_age: 45, customer_weapon: 'Bat', customer_email: '[email protected]', ...
Milos's user avatar
  • 619
19 votes
4 answers
27k views

spread operator converting objects to array

I'm trying to convert a data structure like this: data = { 0:{A:a}, 1:{B:b}, 2:{C:c}, } into a structure like this: [ {0:{A:a}}, {1:{B:b}}, {2:{C:c}}, ] Using the spread operator ...
Turnipdabeets's user avatar

15 30 50 per page
1
2 3 4 5
73