[javascript] Why is "forEach not a function" for this object?

This is probably something really dumb, but I don't understand why this doesn't work.

var a = {"cat":"large"};

a.forEach(function(value, key, map){

Uncaught TypeError: a.forEach is not a function


This question is related to javascript object foreach

The answer is

When I tried to access the result from

Object.keys(a).forEach(function (key){ console.log(a[key]); });

it was plain text result with no key-value pairs Here is an example

var fruits = {
    apple: "fruits/apple.png",
    banana: "fruits/banana.png",
    watermelon: "watermelon.jpg",
    grapes: "grapes.png",
    orange: "orange.jpg"

Now i want to get all links in a separated array , but with this code

    function linksOfPics(obJect){

the result of :



I figured out this one which solves what I'm looking for

["fruits/apple.png", "fruits/banana.png", "watermelon.jpg", "grapes.png", "orange.jpg"]

If you really need to use a secure foreach interface to iterate an object and make it reusable and clean with a npm module, then use this, https://www.npmjs.com/package/foreach-object


import each from 'foreach-object';
const object = {
   firstName: 'Arosha',
   lastName: 'Sum',
   country: 'Australia'
each(object, (value, key, object) => {
   console.log(key + ': ' + value);
// Console log output will be:
//      firstName: Arosha
//      lastName: Sum
//      country: Australia