Question: I am new to JavaScript so I am struggling to even know where to start. Please can someone help me.
I have this array of ingredients:

```
const ingris =  [
  "1 cup heavy cream",
  "8 ounces paprika",
  "1 Chopped Tomato",
  "1/2 Cup yogurt",
  "1 packet pasta ",
  "1/2 teaspoon freshly ground black pepper, divided",
]

```

I am trying to take out for example the `1 cup` or `1/2 teaspoon` (first 2 words of the array) and add it to a new array of objects like below:

```
const ShoppingList = [
  {
    val: "heavy cream",
    amount: "1 cup",
  },
  {
    val: "Tomato",
    amount: "1 Chopped ",
  },
  {
    val: "yogurt",
    amount: "1/2 Cup",
  },
];

```

Answer: 
Using [Array#map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) to map the given array to a new one. `Split` the string to an arry at the spaces. return a new object with the first 2 array-elements as val and the others as amount. For gettuing the last elements use [Array#slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) and [Array#join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join) with a space as glue to connect them to a string.

```js
const ingris =  [
  "1 cup heavy cream",
  "8 ounces paprika",
  "1 Chopped Tomato",
  "1/2 Cup yogurt",
  "1 packet pasta ",
  "1/2 teaspoon freshly ground black pepper, divided",
];

let result = ingris.map(str => {
    let arr = str.split(' ');
    return {val: arr[0] + ' ' + arr[1], amount: arr.slice(2).join(' ')};
});

console.log(result);
```
There are multiple approach but using [`Array.prototype.map`](https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/Array/map) to loop over the array, [`String.prototype.split`](https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/String/split) to turn each string into a array inside the loop, [`Array.prototype.slice()`](https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) to get a slice from the array will help you create what you need. But keep in mind that it currently always get the first 2 words and the words after that. So your ingredients have to be the same way every time

```js
const ingris =  [
  "1 cup heavy cream",
  "8 ounces paprika",
  "1 Chopped Tomato",
  "1/2 Cup yogurt",
  "1 packet pasta ",
  "1/2 teaspoon freshly ground black pepper, divided",
];

const shoppingList = ingris.map(ingredient => {
  const splitIngredient = ingredient.split(' ');
  const amount = splitIngredient.slice(0, 2).join(' ');
  const val = splitIngredient.slice(2, splitIngredient.length).join(' ');
  return { val, amount };
});

console.log(shoppingList);
```