Adding a for loop within a variable declaration [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
Im having trouble looping through the array tabData and storing the new array into 'filteredData'
const filteredData = allData.filter(
({ class }) => tab === tabData[1].tab && class === tabData[1].label,
);
tabData contains the following 0:{Tab:1, Label:'firstTab'} 1:{Tab:2 , Label:'secondTab'} ... and so on

1) You cant use 'class' is reserved word.
2) I guess code should look like:
const filteredData = allData.filter(tab => tab.label === OTHER.label)
Where "OTHER.label" filtering for that label

You’d better take a look at Array.prototype.filter ’doc
var newArray = arr.filter(callback(element[, index[, array]])[, thisArg])
see details

Related

Iterate over array in proxy [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 months ago.
Improve this question
Good day.
I was testing stuff in Javascript with Proxies.
Currently I have this proxy
My question was, how do I iterate over this? I've tried several methods, including object.keys and forEach, which yielded nothing.
Thanks in advance
You need to specify an ownKeys method in the handler you're using to create the proxy or you won't be able to enumerate the keys of the proxy object.
const obj = { test: 'a' };
const handler1 = {
ownKeys(target) {
return Reflect.ownKeys(target);
}
};
const proxy1 = new Proxy(obj, handler1);
console.log(Object.keys(proxy1)) // ['test']
Edit
Actually, you can use Reflect.ownKeys directly also, but you'll want to make sure the behavior is what you expect. For example, it might return length as a key as well.

How te get an element from .fields [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am having trouble getting the property filename from the req.files that I get from the router. Here's what I get:
And here's how I've been trying to get the filename of each (I am only using 2 pictures in this example but I could get more than two images so that's why I am iterating with the forEach)
let arrayImages = [];
if (req.files) {
Array(req.files).forEach(image => {
arrayImages.push(image[0].filename);
})
}
Hi everyone thanks for all the help, i finally figured it out!
let arrayImages = [];
for (const clave in req.files) {
array = req.files[clave]
arrayImages.push(`${array[0].filename}`);
}
that way i've got the fieldname of each element
The root of your data from screen is an object.
So try to code like that:
let arrayImages = [];
if (req.files) {
Object.values(req.files).forEach(arr => {
arrayImages.push(arr[0].filename);
})
}

How to check if all elements in a node list have the same class or the same style property value? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I created memory game. The only problem is that when the game is done and the player wins, it doesn't console.log('win)
Code:
let checkingImages = document.querySelectorAll('.card')
checkingImages = Array.from(checkingImages)
let check = checkingImages.every((each)=>{
each.classList.contains('matched')
})
if(check == true){
console.log('win')
}
Inside your every method, you're only checking for the class's existence, not actually returning anything.
You have to write it like this:
let checkingImages = document.querySelectorAll('.card')
checkingImages = Array.from(checkingImages)
let check = checkingImages.every(item => item.classList.contains('matched'))
console.log(check)
Or like this, if you want to stick to your original answer:
let checkingImages = document.querySelectorAll('.card')
checkingImages = Array.from(checkingImages)
let check = checkingImages.every((item) => {
return item.classList.contains('matched')
})
console.log(check)

How to get this values form this data [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
envelope:'{"to":["reply-to-501-4455#email.ashishbhangade.com"],"from":"Tway"}'
here my object data and i want find values only 501 and 4455 (every time this values are dynamic not static values) so how to get please give me suggestion.
This is way to dynamic values
const split = '{"to":["reply-to-501-4455#email.ashishbhangade.com"],"from":"Tway"}'.split('-')
const code1 = split[2]
const arrWithCode2 = split[3].split('#')
const code2 = arrWithCode2[0]
console.log(code1, code2)
If "reply-to-" and codes length don`t change
const msg = '{"to":["reply-to-501-4455#email.ashishbhangade.com"],"from":"Tway"}'
const code1 = msg.substring(17, 20)
const code2 = msg.substring(21, 25)
console.log(code1, code2)
Perhaps with string.includes?
const envelope = {"to":["reply-to-501-4455#email.ashishbhangade.com"],"from":"Tway"}
console.log(
envelope.to.some(pr => pr.includes("501")),
envelope.to.some(pr => pr.includes("4455"))
)

add and remove html elements to jquery variable [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
i have a JS variable like this:
var elmnts = $('#elm1, elm2, #elm3, #elm4')
how can i add and remove other html elements?
i try this code but there is no result.
elmnts.add('#elm5');
elmnts.remove('#elm1')
$.fn.add returns new collection, it doesn't modify original one. So you should use this syntax.
elmnts = elmnts.add('#elm5');
To remove element from a collection of jQuery objects you can use $.fn.not method:
elmnts = elmnts.not('#elm1');
You should not use remove for this, it's used to delete element from DOM tree.

Categories

Resources