I'm looking to implement a search functionality in my project. I specifically want to search only the values within a JSON object, without including the property names when using regular expressions to evaluate the object's members.
For example, let's consider the following:
var myObj = {
'FirstName': 'Joe',
'LastName': 'Jones',
'Age': 35,
'Address': {
'City': 'Boise',
'State': 'Idaho'
}
};
var myObjValues = JSON.stringify(myObj);
// result: "{"FirstName":"Joe","LastName":"Jones", etc... }"
What I aim for is to have all values from the object combined into a single string separated by a space (or another delimiter) like this:
// result: "Joe Jones 35 Boise Idaho"
The challenge is that the structure of the object can vary, with potentially nested objects at different levels. I want to extract only the deepest attributes that are strings and numbers.
Is there a way to achieve this using the JSON object or any existing libraries? While I considered creating my function to extract and concatenate these values, I'm open to suggestions to avoid reinventing the wheel.
Thank you in advance for any insights or guidance!