Assume I have a JSON object with elements like this:
{"number":"21344"}
and I want to find this exact element through an input form, that allows whitespaces (e.g. "213 44"). How do allow this pattern?
Assume I have a JSON object with elements like this:
{"number":"21344"}
and I want to find this exact element through an input form, that allows whitespaces (e.g. "213 44"). How do allow this pattern?
You can remove all whitespace from a string with:
str = str.replace(/\s/g, '');
In your posted JSON you are apparently trying to search for JSON keys ("number") based on their value ("21344"). If you really want to do that, you could do the following:
var keys = Object.keys(yourJsonObject);
for (var i = 0; i < keys.length; i++) {
if (yourJsonObject[keys[i]] === "21344") {
return keys[i];
}
}