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: 
If you are fine with a function that just returns a pair of numbers (the first match so to speak) whose sum equals the targets value, this might be enough:

```js
function sumPair (arr, target) {
    while(arr.length) {
        let sum1 = arr.shift();
        let sum2 = arr.find(val => sum1 + val === target);
        if (sum2) return [sum2, sum1];
    }
    return null;
}

```
use [`Array.filter`](https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) to find the target sum for all values in an given array. See comments in the snippet.

```js
sumsForTargetInArray();

document.addEventListener(`click`, 
  evt => evt.target.id === `redo` && sumsForTargetInArray());

function sumsInArray(arr, target) {
  // clone the array
  const clone = arr.slice();
  let result = [];

  while (clone.length) {
    // retrieve the current value (shifting it from the clone)
    const current = clone.shift();
    // filter arr: all values where value + sum  = target
    const isTarget = arr.filter(v => current + v === target);
    // add to result. 
    // Sorting is to prevent duplicates later
    if (isTarget.length) {
      result = [...result, ...isTarget.map(v => [current, v].sort())];
    }
  }

  // weed out duplicates (e.g. 0 + 3, 3 + 0)
  const unique = new Set();
  result.forEach(r => unique.add(`${r[0]},${r[1]}`));

  // return array of array(2)
  return [...unique].map(v => v.split(`,`).map(Number));
}

function sumsForTargetInArray() {
  const testArr = [...Array(20)].map((_, i) => i);
  const target = Math.floor(Math.random() * 30);

  document.querySelector(`pre`).textContent = `testArray: ${
    JSON.stringify(testArr)}\ntarget: ${target}\nResult: ${
    JSON.stringify(sumsInArray(testArr, target))}`;
}
```

```html
<pre></pre>

<button id="redo">Again</button>
```