Use es5 Array method instead of multiple loop