I have 3 strings that I need to convert into a single array, from there I want to filter out the type: "bundle"
.
I need to note that I'm using Javascript Code by Zapier and their javascript library is a bit limited as far as the functions that I can use, but this is what I have so far which works if I hard code itemArray
. I'm just having trouble creating my itemArray
from the 3 given strings:
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 return the simple
product types, I'm doing that with the following code:
// 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?