JavaScript Function to Remove a Key From an Array


This a javascript function that will remove a key from an array, the function is called removeKey(). Which is a function that counts the number of times a substring occurs in a string. This will enable you to use this PHP excusive function in your JavaScript codes. To use this function please review "How to Use" and the example usage of the function below.

How to Use

To use this function simply add the function into the bottom of your existing JavaScript code and call the function using the required parameters. Please consult the parameters list below for parameters and there desciptions.

JavaScript Function

function removeKey(arrayName,key)
{
 var x;
 var tmpArray = new Array();
 for(x in arrayName)
 {
  if(x!=key) { tmpArray[x] = arrayName[x]; }
 }
 return tmpArray;
}

Syntax

removeKey(arrayName,key);

Parameter Desciption

ParameterNecessityDescription
arrayNameRequired.Name of array.
keyRequired.Key in array you want to remove.

Example Usage of removeKey()

Example 1:
array:
var tempArr = new Array();
 
tempArr['removeMe'] = 'remove me';
 
tempArr['dontRemove'] = 'dont remove me';
function call:
tempArr = removeKey(tempArr,'removeMe');
results:

Developer

This function was developed by Sean Gallagher. He is a website designer, developer and search engine optimizer who currently runs a web development, design and SEO company based out of the Pittsburgh area. To visit his company websites go to Pittsburgh SEO, Pittsburgh Website Design, Atlanta Website Design.

License

This function is released under the free software licenced GNU General Public License.

Copyright © 2008 Sean Gallagher

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see .