Home > Blockchain >  How to get the value of iterating object? Without using foreach and dot operator
How to get the value of iterating object? Without using foreach and dot operator

Time:09-29

For example:

var myObject = {
 name : 'David',
 age: '30,
 salary:'30000'
}

I need answers like: My name is David, I'm 30 years old. I earned monthly 30000.

Note: Without using '.' DOT operator and for and foreach.

CodePudding user response:

This should work:

var myObject = {
    'name' : 'David',
    'age': '30',
    'salary':'30000'
 };
console.log('My name is ' myObject['name']);

Here is the JSFiddle Example: Link

CodePudding user response:

var myObject = { name : 'David', age: '30', salary:'30000' } //object destructure

let {name, age, salary} = myObject;

console.log(my name is ${name})

CodePudding user response:

var myObject = {
    'name' : 'David',
    'age': '30',
    'salary':'30000'
 };
console.log(`My name is ${myObject["name"]}, I'm ${myObject["age"]} years old. I earned monthly ${myObject['salary']}.`);
  • Related