hello every one
i would like to create a function to chek if a value is inside array i d this but is not working
hello every one
i would like to create a function to chek if a value is inside array i d this but is not working
Can you copy the data using the "Copy Value" button
and paste the msg data into a reply (inside a code block).
It is hard to recreate data from a screenshot.
Also, please dont post pictures of code (they are not searchable and most people wont re-type your code to help you solve it)
Thank you Steve .... i did thisfor now, i'm really new on node-red but looking in the forum i had lot of help
{"":"14h00-22h00"}
var Pippo ;
input = msg.payload;
var vroeg = input.includes("06h00-14h00",0);
var late = input.includes("14h00-22h00",0);
if(vroeg === true) {
Pippo = 1;
}
if (late === true){
Pippo = 2;
}
msg.payload = Pippo;
return msg;
where is this data being generated? It is most odd!
Anyhow, you can use the Array.find
function to search an array of objects.
e.g:
let pippo
const input = msg.payload
const vroeg = !!input.find(e => e[''] === '06h00-14h00')
const late = !!input.find(e => e[''] === '14h00-22h00')
if (vroeg === true) {
pippo = 1
}
if (late === true) {
pippo = 2
}
msg.payload = pippo
return msg
the data are generated in a sheet of excel i reading a woorkbook if i found this data i will send to a Siemens plc to start warmup of a gloe machine
The data object is not really very valid as an object. That's why your includes doesn't work. You are looking in the array for a string but the array contents are objects with a very odd key ""
.
I would suggest fixing the Excel data output.
thank you very much for suggestion, i just used the function from Steve and is working
thank you very much again