Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
var layers = {}; //Add new layer layer.markers = new L.Group(); layer.Name = t; layers.layer = layer;
Gives an error layers.length is still 'undefined'. Why is it doing that ? I have verified in log that layers contains an item.
layers
length
layers is not an array. If you want to keep it as an object literal, and check if it's empty, try defining something like this:
Object.isEmpty = function(obj) { for (var p in obj) if (obj.hasOwnProperty(p)) return false; return true; };
And use
if (!Object.isEmpty(layers)) { ...
instead.
Add a comment
You're not adding to the array. The last line should be:
layers.push(layer);
Simple question. layers is an object not an array.
What you needs to do is replace layers to following.
var layers = new Array();
And replace adding layer code from
layers.layer = layer;
to
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
layersis not an array - it's a generic object, and objects have nolength