1

I have an array like this

var Data = [{
"words": [
    "dolor",
    "sit",
    "amet",
    "consectetur"
],
    "description": "Lorem Ipsum."
}, {
"words": [
    "adipisicing",
    "elit",
    "sed",
    "do"
],
    "description": "Lorem Ipsum."
}];

How can I join all the words into one string, separated by single pipe symbol "|" ? The desired output should look like this: (dolor|sit|amet|consectetur|adipisicing|elit|sed|do)

1 Answer 1

7

Do This

Data.map(function(obj){ return obj.words.join("|") }).join("|");

Returns "dolor|sit|amet|consectetur|adipisicing|elit|sed|do"

Sign up to request clarification or add additional context in comments.

1 Comment

Regarding IE support, map is only supported in IE9 and up. There's a polyfill here if you need to support older IEs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.