I have some code that produces undefined values in an array making no sense.
here is the code:
gcc_py = 8;
gcc_pyd = 12;
var aci = 360/gcc_pyd;
var parcalar = new Array();
var renkler = new Array();
for(var i = 0;i<gcc_pyd;i++){
parcalar.push(aci);
renkler.push('#000');
}
console.log(parcalar);
console.log(renkler);
console.log(parcalar) outputs this:
[
Object
,
Object
,
Object
,
Object
,
Object
,
Object
,
Object
,
Object
,
Object
,
Object
, undefined × 2]
do you have any idea for the undefined values in the array?
I guess you are changing the arrays afterwards. The console will reflect these changes, e.g. then showing objects instead of numbers and strings. Also, when deleting properties from an array (via
delete, see Deleting array elements in JavaScript – delete vs splice), they will still show up as initialised but empty (see What is "undefined x 1" in JavaScript?).