Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

asked on

jQuery Detect When Last Value is Found?

How do I detect when the last value is found in the below function? I don't do jQuery!  What I want is to add a pipe delimiter after each value is found but not the last value. So I'd have for example if it returns 3 values then I will get ==> value1|value2|value3 . The example below uses a console.log but it will actually be returning the value in a variable, in real life.

 $(function() {
	        $('[class*="solid-shape-large-rating-"]').each(function(i, e) {
		        var result = this.className.match(/solid-shape-large-rating-(.*?)\s+/);
		        console.log(result[1]);
			    
	        });
       });

Open in new window

Avatar of leakim971
leakim971
Flag of Guadeloupe image

$(function() {
    var results = [];
    $('[class*="solid-shape-large-rating-"]').each(function(i, e) {
        var result = this.className.match(/solid-shape-large-rating-(.*?)\s+/);
        console.log(result[1]);
        results.push(result[1]); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push
    });
    console.log(results);
});

Open in new window

Avatar of MJ

ASKER

Hi Leakim,
No pipe delimiter. I want the values separated by a pipe as in my example, I will get ==> value1|value2|value3 .

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MJ

ASKER

Thank you sir!