0

I am trying to delete an element /the last element from an array in angular. This is what a looks like

0: {geometry: {…}, symbol: {…}, attributes: {…}, infoTemplate: null, _suspended: false, …}
1: {geometry: {…}, symbol: {…}, attributes: null, infoTemplate: null}
2: {geometry: {…}, symbol: {…}, attributes: null, infoTemplate: null}

this is my function

_pushAddOperation: function (a) {
            console.log("a",a);
            m.forEach(
                a,
                d.hitch(this, function (a) {
                    var b = a.attributes || {};
                    b[this._objectIdName] = this._objectIdCounter++;
                    a.setAttributes(b);
                    this._graphicsLayer.add(a);
                    if (b  === x) {
                        //deletion
                        a.splice(-1,1);
                    }
                })
            );
        }

I am getting an error saying a.splice is not a function and I don't understand why

_pushAddOperation: function (a) {
            console.log("a",a);
            m.forEach(
                a,
                d.hitch(this, function (k) {
                    var b = a.attributes || {};
                    b[this._objectIdName] = this._objectIdCounter++;
                    k.setAttributes(b);
                    this._graphicsLayer.add(k);
                    if (b  === x) {
                        //deletion
                        k.splice(-1,1);
                    }
                })
            );
        }

2 Answers 2

1

You are declaring a function _pushAddOperation that receive a parameter called a (array), but whiting this function you are declaring a new function that receive a parameter called a(object) again. So you are actually trying to use splice for this object

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

1 Comment

So, if I understand you correctly you are saying I should use another name for the second a variable? I've edited my question above.
0

You have two a variables, one in the outer function and one in the inner function. The a you are trying to splice appears to be an object. Not sure, since I don't know what the hitch method takes.

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.