Question: I have set of codes where i need to insert multiple rows in `MySQL` using procedures

```
<?php
$conn = new mysqli("localhost","root","","company");
$array_item = 'Array
(
    [0] => Array
        (
        [user_name] => VANITHA
        [adddress] => 
        [mobile_no] => 8877665544

        )

    [1] => Array
        (
       [user_name] => VANITHA1
        [adddress] => rere
        [mobile_no] => 8877665544
       )
);

';
$sql=mysqli_query($conn,"CALL addnew($array_item)");

```

procedures codes are as follows

```
 CREATE  PROCEDURE addnew(IN ArrayDemo VARCHAR(100))

    BEGIN  

    insert into geektable (user_name,adddress,mobile_no) 
                    values(user_name,adddress,mobile_no);  

    END

```

Answer: 
```
const targetSum = (arr, target) => {
    const first = arr.find((v,i,a) => arr.includes(target-v) && (arr.indexOf(target-v) !== i));
    return first ? [first, target - first] : null;
};

const values = [1,2,3,4,5,6,7,8,9];
console.log(targetSum(values, 1)); // null
console.log(targetSum(values, 2)); // null
console.log(targetSum(values, 3)); // [1, 2]
console.log(targetSum(values, 15)); // [6, 9]
console.log(targetSum(values, 20)); // null

```
I changed for loop with forEach (more efficient) and there is no need for the copyArray array so I removed it. I also changed pop() with shift(), I think you want to shift the array and not pop-it (if I understand the task correctly).

```
function targetSum3(arr, target) {
        let newArr = [];
        arr.forEach(element => {
            let x = Math.abs(element - target); // calc x
            arr.shift(); // removes first element from arr (current element)
            if (arr.includes(x) && (arr.indexOf(x) != arr.indexOf(element))) {
                newArr.push(element);
                newArr.push(x);
                return;
            }
        });

    return newArr;
}

```