0

For example I have brunch of data like below:

HTML:

<p class="test-tag">abc+dd</p><p class="test-tag">gf+sx</p>

and store in JavaScript in array form

var text = ["abc+dd","gf+sx"];

And I must return an array like below:

var res = [["abc", "dd"],["gf", "sx"]];

What's the best way to do this?

1
  • 1
    Are you asking how to best generate the P tag from the give array RES? Commented Jun 3, 2016 at 2:35

2 Answers 2

1

Something like below should work..

var finalArr = [];
$('.test-tag').each (function (){
var value = $(this).text;
var subArr = value. map(function (b){
    return b.split('+');
  })
finalArr. push(subArr);
})
Sign up to request clarification or add additional context in comments.

Comments

0

You can map over your array and use split:

Example JSBin

var text = ["abc+dd","gf+sx"];

var array = text.map(function(v) {
  return v.split('+');
});

Comments

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.