0

I need to add any number to random array to the preset position and and move elements after him. I just wrote code for random array how to continue?

var CreateArray = (...lengths) => lengths.map(length => (
  Array.from({
    length
  }, () => Math.floor(Math.random() * 3000000))
));
var randomarrays = (arrs) => {
  arrs.forEach(arr => {
    randomarray(arr);

  });
};
lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
rollback
  • 111
  • 5
  • Use splice https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice – vijayst Jun 21 '18 at 16:26
  • can you explain more? i know about splice, but how to use it with that code that generate random array? – rollback Jun 21 '18 at 16:28
  • So you are asking how to insert a value into an array at a given index? If yes, dupe of https://stackoverflow.com/questions/586182/how-to-insert-an-item-into-an-array-at-a-specific-index – epascarello Jun 21 '18 at 16:32
  • do you know any other method without "splice"? – rollback Jun 21 '18 at 16:33

0 Answers0