Avatar of MJ
MJ
Flag 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

JavaScriptjQuery

Avatar of undefined
Last Comment
MJ

8/22/2022 - Mon
leakim971

$(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

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
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MJ

ASKER
Thank you sir!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes