How to get this values form this data [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 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"))
)

Related

How to convert NaN value to 0 inside app.post in .js file [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 last year.
Improve this question
In below code question1 value is coming as NaN. I want to convert it to 0 but I am not able to do it using parseInt. How can I do this?
app.post('/auth/total',function(req,res){
console.log(req.body);
const { question1, question2, question3, question4} = req.body;
let total1 = parseInt(question1) + parseInt(question2)
let total2 = parseInt(question3) + parseInt(question4)
//some code to insert data in db and render the view
});
you can do this:
let total1 = (parseInt(question1) || 0) + (parseInt(question2) || 0)
this will convert any falsy value to 0

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)

String's split method shows undefined [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
I am trying to get all characters starting from = inside url:
let url = this.$route.query.item
console.log(typeof(url)) // outputs string
let status = url => url.split('=')[1]
it shows split as undefined. What is the problem and how can be it fixed?
Here is what you want:
let url = "foo=bar";
console.log(typeof (url)) // outputs string
let status = url => url.split('=')[1]
console.log(status(url));// "bar"
I think your this.$route.query.item does not contain = character. if you are looking for current url try this may be
let url = this.$router.currentRoute;
console.log(url); // check if this is the url you expect
let status = 'url does not contain = char';
if(url.includes('='){
status = url.split('=')[1];
}
console.log(status);
note: if you actually need to split this.$route.query.item, console log it and check if it contains = or perhaps add a check for it.

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

Categories

Resources