Javascript Foreach Function Item Index Array Matlab