computed property in javascript

/*
Computed Property Names is ES6 feature which allows 
the names of object properties in JavaScript OBJECT LITERAL NOTATION
to be determined dynamically, i.e. computed.
*/

let propertyname = 'c';

let obj ={
	a : 11,
    b : 12,
    [propertyname] : 13
};

obj; // result is  {a:11 , b:12 , c:13}

//or incase if you want a as your object you can set in this way

let a_value = {
	[obj.a] = obj // a_value's key name as (a) and the complete (obj) present above itself will act as a value
};

3.67
9
Neil Stead 105 points

                                    /*
Computed Property Names is ES6 feature which allows 
the names of object properties in JavaScript OBJECT LITERAL NOTATION
to be determined dynamically, i.e. computed.
*/

let propertyname = 'c';

let obj ={
	a : 11,
    b : 12,
    [propertyname] : 13
};

obj; // result is  {a:11 , b:12 , c:13}

//or incase if you want a as your object you can set in this way

let a_value = {
	[obj.a] = obj // a_value's key name as (a) and the complete (obj) present above itself will act as a value
};

3.67 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
javascript computed property javascriptinfo access computed in javascript what is computed property name javascript what is computed property in javascript set computed property javascript JavaScript computed properties examples and explanations in Objects what is computed property names js computed properties definition javascript computed property name js js computed property names Why use computed property in js return computed property javascript computed property js javascript computed properties javascript object computed property vue computed property use js to computed a property a computed property name javascript what are computed properties in javascript what is the use of computed property names in js computed property javascript computed properties javascript javascript es6 computed property computed property js class computed property names js js class computed property js computed property syntax computed property get set javascript computed property syntax javascript Computed Property computed components properties computed properties how to call function in computed properties computed property to return method syntax for computed key computed property names javascript js computed property computed property syntax computed values in javascript initializer in js js computed variables computed javascript es6 computed property name id computed property in js javascript initialise object how to refer to initial x in object computed property in javascript computed property names in javascript computed property name javascript
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source