jQuery - loop through sku content and manipulate the fuck out of it

grab skus from page - put in array - slice off the first and last characters. Plus some pipe joinery.

by James Hooper

HTML

<h2>SKUs to put in array</h2>

<span class="product-sku">(6940D)</span>

<span class="product-sku">(12345)</span>

<span class="product-sku">(54321)</span>

<span class="product-sku">(78945)</span>


<h2>Result</h2>

<div class="result">

</div>

JavaScript

// empty array
var skus = [];

// loop through all the skus 
jQuery(".product-sku").each(function() {

	// Push 'em in the array. Slice off the brackets while we're at it too
  skus.push(jQuery(this).text().slice(1, -1))
  
});

console.log(skus);

// Light your pipe. Add some space either side of the pipe if you wish.
var skusPipe = skus.join(" | ");

jQuery(".result").html(skusPipe);