-2

enter image description here

I have these type of array in javascript.Now i want to remove the value from array which name is "PropertyType[]".How to do it.Here i upload the picture of array.Here in Newremoveurl array i get the array value.

var Newremoveurl = [];
        var Parant_name = 'PropertyType';
        $.each(Removeurl_array, function( key, value){
            var decoded_key = decodeURI(value);
            if ($.inArray(Parant_name, Newremoveurl)!='-1') {

            } 
            Newremoveurl[key]=decoded_key;
        }); 
Eddie
  • 25,279
  • 6
  • 26
  • 53
Code ninja
  • 37
  • 1
  • 7

2 Answers2

1

you can filter your array to remove these with standard javascript for an exact match - you can remove like this

const filteredResults = myArray.filter(item => item === "PropertyType[]")

or for values which contain a string

const filteredResults = myArray.filter(item => item.indexOf("PropertyType[]") ===-1)
developer
  • 566
  • 3
  • 11
0
for (var i=myArr.length; i--;) {
     if (myArr[i].indexOf("PropertyType")>=0) break;
}

Value of i will be -1 if PropertyType* does not exist, or else it would be the index of the element.

Then cut the element from the array with

if (index > -1) {
    myArr.splice(index, 1);
}

You can run this solution till the value of i becomes -1, then your array would hopefully be free of the element you do not require.

Farhan Qasim
  • 960
  • 4
  • 18