So basically i want to check if my data (which is in JSON Format) has a value which is a primitive. So let's take an Example: I get data that looks like this: {name: Artikel, value: {"ArtNr": 1234}} and i want to check if 1234 is primitive or not. I also want to differentiate if the result is an Array with Primitives in it or an Object. Is that possible?
function isObjectContainingPrimitiveValues(test) {
let values = Object.values(test);
for (let i of values) {
console.log(i);
return (typeof i === 'string' || typeof i === 'number' || typeof i === 'boolean' || typeof i === null || typeof i === undefined);
}
}
UPDATE
So with the awesome help of MaxK i have built a isResultContainingPrimitiveValues()
Function which checks my data for Primitive/ Primitive Arrays and or Objects. The following part is the trickiest at least with my understanding. The following Example will hopefully help you understand my problems better.
So my let namesSplit = treeNode.name.split('.');
variable splits the data it gets and has as a result of nameSplit : Artikel,Artnr
. Next i defined a key variable let key = namesSplit[0];
which has key : Artikel
as a result. Than i define a contextEntry variable let contextEntry = exprData.contextEntry.find(_x => _x.name === key);
and has contextEntry : {"name":"Artikel","value":{"ArtNr":123}}
as a result. Now i want to check: if there's another split namesSplit.length > 1
check isResultContainingPrimitiveValues()
. If it is primitive, throw an error, if it is an object -> get values from it and if it is an array -> get values form there. I know it's a lot but from all the confusing stuff i can't seem to think clear, so i appreciate every help i can get.