Skip to main content

All Questions

0 votes
1 answer
34 views

What is the difference between giving character with quotes as key and just character as key of property of an object in javascript [duplicate]

const first= {a: 2, b: 3} const second= {"a": 2, "b": 3} Even though both examples given above print the same in console, I can't access the values of those objects the same way. ...
Bhargav v's user avatar
0 votes
2 answers
120 views

Render javascript file with inline javascript

I am having the following *.js file: var text = ` This is a test ${Company.Name}. ` module.exports = { text }; My main file looks like the following: const Company = {} Company.Name = "Apple" ...
Carol.Kar's user avatar
  • 5,175
3 votes
3 answers
84 views

Modern syntax vs old syntax for loops

I have this code that is working successfully using modern syntax. function maxChar(str) { const charMap = {} for(let char of str){ charMap[char] = 1 } return charMap } console.log(...
claudiopb's user avatar
  • 1,070
0 votes
2 answers
639 views

Adding a method to a prototype called 'speak'

Keep getting the error: Should add a method to the prototype called speak Expected 'DogsaysWoof' to be 'Dog says Woof'. Thought I nailed it but something is missing. I put the spaces "" between the ...
DangerousWithRocks's user avatar
5 votes
7 answers
17k views

Creating an array from object properties with Object.keys() vs Object.values()

Here's an object of cat breeds, and the number of cats in each: const cats = { abyssinian: { number: 23 }, persian: { number: 12 }, siamese: { number: 7 } }; Suppose I wanted ...
Robin Métral's user avatar
2 votes
6 answers
286 views

How to sum objects properties inside objects?

I am trying to sum the total of matches and participants of each cup in this object: { "Cup_1": { "bronze": { "matches": 3, "participants": 289 }, "...
RogerHN's user avatar
  • 594
3 votes
2 answers
2k views

Iterate and change all occurrences of given fields in JSON

I have a JSON object. I need to change values of all occurrences of a given field of it. For example: { email:"[email protected]", person: { email:"[email protected]" }, mother: { name:...
Jacek Wojcik's user avatar
  • 1,253
2 votes
1 answer
40 views

Is it possible to dynamically build variables in Javascript [duplicate]

I am trying to figure out the best way to dynamically build variables. I have a database that looks like this: One record: ans1 ans2 ans3 res1 res2 res3 I have a function that checks the answer ...
Jason's user avatar
  • 1,121
1 vote
4 answers
392 views

Javascript iterate Json Array to get values

I have a below JavaScript var arr = []; arr.push({0:'Zero'}); arr.push({1:'One'}); console.log(Object.keys(arr)); console.log(Object.values(arr)); //Not getting expected result I want to print keys ...
Digital's user avatar
  • 571
7 votes
3 answers
3k views

JavaScript Symbol type: (non-string object keys)

What is the "Symbol" javascript type as mentioned in this ECMAScript 6 draft specification? To quote the spec: The Symbol type is the set of all non-String values that may be used as the ...
Web_Designer's user avatar
  • 73.9k