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
- once frozen cannot unfreeze object.
- you should never assume data coming client has not been tampered with. validate server side.
Comments
Post a Comment