Text value of javascript objects are converted by default

This might be slightly offtopic to OSC.

I would like to just get a part of an object, where the key matches a string.

obj = {
"test1#xxx" : "00 00",
"test2#yyy" : "01 54",
....
}

in a small function

Objects.keys(obj).forEach(function(key,value) {
if (key.includes('#xxx')) {
tempObj[key] = value;
}
})

now the value field messes up the hex string (including blank, and interprets this as number), i just want to get it 1:1. How can i avoid this conversion?

Thanks!

How are displaying it currently ?

just 2 digits (54) the "outer right" 2 chars

I mean how do you obtain that ? (the above explanation is not enough to reproduce your issue)

The obj is declared in the custom module(it does not change). The object is sent via OSC listener, (values property).When pressing a button in the gui, this 2 byte hex is sent out(via osc outfilter) to the hardware device. i saw the values via console log(and in the values prop too)

will try out (that should trigger a string conversion)
< value +""

I'm sorry but you haven't explained yet what you're doing with the value that might explain the issue.

And i thank you for your patience, finally i have found it... (writing it here, in case someone need this too..)

this code forced a number conversion in "value" (even adding an empty string did not work)

Objects.keys(obj).forEach(function(key,value) {
if (key.includes('#xxx')) {
tempObj[key] = value;
}
})

the part of the whole object is sent via OSC Listener to a values prop of a switch .

obj = {
"test2#yyy": 9
..}

9 as value is received instead of "00 09"

so i took instead the value of the whole object:

tempObj[key] = obj[key];

I have to learn a lot about js it seems.. :slight_smile:

I get it now !

Objects.keys(obj).forEach(...)

Iterates over an array containing only your object's keys, the issue was not that the value was being converted, but that the function called by forEach is supposed to have only one argument (the item's value in the array, not in the object).