How te get an element from .fields [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 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);
})
}

Related

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)

Retrieving specific objects from a Fetch API (JavaScript) - Re post [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
Edited question: Trying to write the code needed to display only the title and description of the book returned.
I have attempted the following, and am met with a response of, "Cannot read property 'title' of undefined." The same happens to 'description'(line 6) when line 5 is removed.
require('isomorphic-fetch');
let items = [];
fetch("https://www.googleapis.com/books/v1/volumes?q=isbn:0747532699")
.then(res => res.json())
.then((result) => {
items = result.items;
console.log(items.volumeInfo.title)
console.log(items.volumeInfo.description)
}),
(error) => {
console.log(error);
}
What am I doing wrong, and how can I fix it?
items is an array. You would need to access it like this:
result.items[0].volumeInfo.title
More specifically, you could loop the results
for (let i = 0 in items) {
result.items[i].volumeInfo.title; //do something here
}
The issue here is result.items is actually an array not an object. Thus we can not simply call volumeInfo property on an array. If you want first array values then you can simply do:
const items = result.items;
if(items && items.length){
console.log(items[0].volumeInfo.title)
console.log(items[0].volumeInfo.description)
}
Or, if you want the info from all the items, then you can loop over it like:
const items = result.items;
items.forEach(function(obj,index){
console.log(obj.volumeInfo.title)
console.log(obj.volumeInfo.description)
});

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"))
)

Adding a for loop within a variable declaration [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 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

How to fill empty array with "for loop" and "prompt(' ')" in javascript [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 6 years ago.
Improve this question
I have written:
var arr = [];
for (i = 0; i < 5; i++) {
var name = prompt('please, enter your name');
arr.push(name);
}
console.log(arr);
But it is does not work. It asks me only once, but I need to make array with five names.
It worked for me. Are you using Google Chrome to test. Maybe something for above it is interrupting. Try it on a new Javascript File. If you're using Chrome to test what is the log saying Ctrl + Shift + J let me know.
Thanks :)
It works ok, it is maybe bug in jsbin.com. Sorry.

Categories

Resources