All Questions
10 questions
0
votes
1
answer
37
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. ...
0
votes
2
answers
131
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"
...
3
votes
3
answers
88
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(...
0
votes
2
answers
652
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 ...
5
votes
7
answers
18k
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 ...
2
votes
6
answers
287
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
},
"...
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:...
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 ...
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 ...
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 ...