i am having a function like below
var resultObject = {
testResult: $('.test').map(function() {
return {name: $(this).text(), no:'1'};
}).get()
};
console.log(resultObject);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="test">test1</div>
<div class="test">test2</div>
<div class="test">test3</div>
<div class="test2">1</div>
<div class="test2">2</div>
<div class="test2">3</div>http://stackoverflow.com/questions/ask#
The field "no" should be according to the class="test2"but it doesn't seem like i can do something like .map() in .map()
Big Updated!!
I see there are so many answer below and most of them can solve the issues and I just figured out a way to fix my problem too.
Please let me share it and see if there's anything else i shall improve.
var test1= "";
$(".test" ).each(function( index ) {
test1 = $(this).text();
});
var test2= $('.test2').map(function() {
return {name: $(this).text(), no:test1};
}).get()
var sovCategories = test2;
eachandmapwhere one loop would be do the same thing ...