array/insert-at module

requires

  • Array() class

    global

    methods

    • .insertAt(index:number, item:any+)

      Insert items into array

      index
      Where to insert items. Any number greater than array.length will be set to length. Negative number will insert from the end of array.
      item
      All additional arguments are inserted

code

/* istanbul ignore if */
if (typeof define !== "function") {
	var define = require("amdefine")(module);
}

define(function (require) {
	"use strict";

	/*meta({
		"name": "Array",
		"type": "class",
		"global": true
	})*/

	require("../class/method");
	require("./from");

	var meta = require("../meta");
	
	Array.method(
		meta({
			"name": "insertAt",
			"description": "Insert items into array",
			"arguments": [{
				"name": "index",
				"type": "number",
				"description": "Where to insert items. Any number greater than array.length will be set to length. Negative number will insert from the end of array."
			}, {
				"name": "item",
				"type": "any",
				"repeating": true,
				"description": "All additional arguments are inserted"
			}]
		}),
		insertAt
	);
	
	function insertAt () {
		var args = Array.from(arguments);

		// howMany = 0 into args so no items are removed
		args.splice(1, 0, 0);

		return this.splice.apply(this, args);
	}
});
Page built with api-meta