1

I have a collection with following entry

{ 
    "_id" : "6z2pQDYozQxEyPZYv", 
    "userId" : "b2dQ6SuPrwmPsLsg8", 
    "communicatingWith" : [ "KMT74bWPoZxDSKdrx", "KMT74bWPoZxDSKdrx" ] 
}

when I query mongo through meteor for the field communicatingWith , if I do a console.log(communicatingWith), the output is [ 'KMT74bWPoZxDSKdrx', 'KMT74bWPoZxDSKdrx' ].

Even when I do console.log(communicatingWith.length) the output is 2

But when I do

communicatingWith.each(function(item){console.log(item)})

it throws error saying

Exception while invoking method 'createPrivateMsgHanger' TypeError: Object KMT74bWPoZxDSKdrx,KMT74bWPoZxDSKdrx has no method 'each'

Can you please help me understand where things are wrong?

3 Answers 3

1

.each is a jQuery function pure javascript uses Array.forEach(function(item) { //do something here})

Sign up to request clarification or add additional context in comments.

Comments

0

I could get around this problem using the following statement let arr = Array.from(loggedInUserHanger.communicatingWith); once I have the arr, I can use all Array functions

Comments

0

Another solution would be using forEach. I don't remember seing each in JS before https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.