I have 3 strings that I need to convert into arrays, from there I want to filter and then combine them using javascript, I need to note that I'm using Zapier and their javascript library is a bit limited but this is what I have so far:
Strings:
var type = 'bundle, simple, simple';
var name = 'Product1, Product2, Product3';
var price = '1.99, 2.99, 3.99';
I need to figure out how to convert the above 3 strings above into the following array using javascript:
var itemArray = [
{type:"bundle", info: {name: "Product1", price: "1.99"}},
{type:"simple", info: {name: "Product2", price: "2.99"}},
{type:"simple", info: {name: "Product3", price: "3.99"}}];
From there I'm looking to filter out the bundle
product type and only pass along the simple
product arrays, I'm doing that with the following:
// Using a for loop
var filtered = [];
for (var i = 0; i < itemArray.length; ++i) {
var item = itemArray[i];
if (item.type == 'simple') filtered.push(item);
}
return {filtered}; //this returns just the 2 simple product type arrays
So my question is, how do I take those 3 strings that I began with and convert those into my itemArray
format using javascript?