javascript - How to protect array? -


i have problem site. have make website using this , laravel. so, using jquery plugin, have set "prices" array. , now, problem, how can protect prices? want "anti editing" developer console, how? maybe can "skip" javascript code? thank in advance.

you can lock object using object.freeze on it

var arr = [1, 2, 3]; // [1, 2, 3]  object.freeze(arr); // can't modify arr[1] = 100; // can't delete delete arr[1]; // can't add arr[3] = 4; // arr.push(5); // `throw` typeerror // same @ freeze time arr; // [1, 2, 3] 

freezing doesn't flow down nested objects, if wish children frozen need iterate on properties of object too.


please note

  1. once frozen cannot unfreeze object.
  2. you should never assume data coming client has not been tampered with. validate server side.

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -