[Solved] I want to loop through an array but I don’t want to use for

You can use Array.prototype.map for this. In your case: suspects.map((name) => { let suspectObj= CreateSuspectObjects(name); suspectsList.push(suspectObj); }); If you need the index in the future you can also do: suspects.map((name, idx) => { let suspectObj= CreateSuspectObjects(name); suspectsList.push(suspectObj); }); 4 solved I want to loop through an array but I don’t want to use for

[Solved] Ruby code doesn’t work [closed]

I checked your codes and found some problems: num_array.reverse.each_with_index { |value , index| if index % 3 == 0 && num_array[index] != 0 num_string = num_string << ones_place[value-1] elsif index % 3 == 0 && value > 0 && num_array[index] != 0 num_string = num_string << other_place[index/3] << ones_place[value-1] elsif index % 3 == 1 … Read more

[Solved] return value from loop

To return a value from a loop, use break value: def my_def(port) @hsh.each do |k, v| break k if v == port end end In general, @Stefan’s comment solves this particular problem better: def my_def port @hsh.key port end solved return value from loop

[Solved] jQuery .each() function – Which method is optimized? [closed]

I’d use map(), because it’s there for this very purpose (no need for temp array) var textLinks = $(“a”).map(function(){ return $.trim($(this).text()); }); Edit: If I was looking for the fastest solution I’d start with ditching jQuery 😉 var textLinks = (Array.prototype.slice.call(document.links)).map(function(a){ return a.textContent || a.innerText }) Or if you’re concerned about browsers without Array.map use … Read more