• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

126
Views
Deleting a non-string in js object

Let's say I have the following object:

const a = {a: 1, 0: 2};
delete a.a; // this works
delete a.0; // this errors (I suppose expecting a['0'] and not a[0])

Does the method deletion form of obj.key only allow deletion of a string key? And if it's a non-string type, is the only way of doing deletion via the key lookup method of obj[key] ?

about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

According to MDN:

In the object.property syntax, the property must be a valid JavaScript identifier.

... where ...

... identifiers are case-sensitive and can contain Unicode letters, $, _, and digits (0-9), but may not start with a digit.

So, answering your question, property with name 0 can be only accessed with key notation.

about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error