All Questions
26
questions
1
vote
1
answer
179
views
How can you reuse an object property in a loop in javascript?
I was trying to reuse an object property in a loop. Is this the right way? I'm always getting an undefined error. The properties I want to use are 'field_id' and 'field_text'. I'm not sure if it ...
0
votes
1
answer
31
views
Looping through an array and setting each element as a property of an object messes with the order
I have an array containing some IDs:
let ids = [ '184', '085', '241', '086', '087', '165' ];
and an empty object - let data = {};
I am looping through the array and setting each of the elements as a ...
0
votes
4
answers
77
views
Loop to remove card from player's hand not working
I'm working on a card game. It has a playerHand array which consists of 7 card objects with the properties Value suit and cardName. These are rendered on the screen as 7 divs with the shared class ....
0
votes
1
answer
54
views
Iterating through Objects of Objects Javascript?
I have this object structure that I want to iterate through to make a node of all the "properties." So I want to make nodes for the objects 1,2,5, and 8 but not for the arrays. I have this ...
1
vote
4
answers
47
views
Checking if any variable in object have null/undefined/emptyString('')
I want to check if there is any empty field or not before submitting form. But the problem is I have variable number of fields (value1,value2...) So i can not use simple if statement. So is there any ...
1
vote
5
answers
138
views
finding highest value in an array of objects not exceeding a certain value - Javascript
I have a an array of objects and want to find the player with the highest score which also does not exceed a certain score (for example 20 points). How do I do so?
let playerScores = [
{ ...
1
vote
2
answers
34
views
Javascript properties end up in loops
the following code will add the property 'id' to the object 'obj'. When calling the getter and setter there will be a console.log execution.
let obj = {}
Object.defineProperty(obj, 'id', {
...
8
votes
2
answers
17k
views
How To Loop Through A Nested Object [duplicate]
Hi there i have an nested object that looks like this
var dogTypes = {
GermanShepard {color: "black and white"},
Beagle {color: "brown and white"},
cheuwahwah {color: "green and white"},
...
3
votes
3
answers
69
views
Getting name from nesting arrays from matching arrays
I have some arrays, and if they contain similar values, I would like to return the name of those arrays.
var x = {
"food": ['bacon', 'cheese', 'bread', 'tomato'],
"utilities": ['...
0
votes
4
answers
2k
views
Return object in array if contain key value pairs
How do you return objects in an array if it contain specific key-value pairs?
I need to return it if it has all key value pairs given, not just one.
for example,
This function with the array of ...
1
vote
1
answer
56
views
Object Not Maintaining Assigned Values
I am looping through an array to create another array of objects in a modified format.
for (i = 1; i <= 37; i++) { // create 37 boxes for days of the month and nearby dates
room_reservations[i] =...
-3
votes
3
answers
2k
views
How to loop all properties from object passed as parameter and change their values?
I'm passing in an object like:
obj = {a:1,b:2,c:3}
I am trying to change 1/2/3 to changed
Here is my code:
var func = function(change) {
for (var property in change) {
if (func....
3
votes
1
answer
41
views
Javascript - Trying to contain objects inside dynamic properties
I have a function that creates an object and saves it as an ID in another object:
var enemyList = {}; //global var
Enemy = function () {
var id = Math.random(); //random id
var enemy = {
...
0
votes
1
answer
467
views
Search for Matching Properties and Equivalent Property Values
I am working on a task for freecodecamp and find myself very stuck. The task is to:
"Make a function that looks through a list (first argument) and returns an array of all objects that have ...
1
vote
3
answers
10k
views
How do I loop through a multi-level object in JS? [duplicate]
How would I loop through each of the value: properties in the object below? My attempt in the console.log below obviously does not work, but that is what I was trying to accomplish. console.log(key) ...