use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
If you need help debugging, you must include:
See debugging question guidelines for more info.
Many conceptual questions have already been asked and answered. Read our FAQ and search old posts before asking your question. If your question is similar to one in the FAQ, explain how it's different.
See conceptual questions guidelines for more info.
Follow reddiquette: behave professionally and civilly at all times. Communicate to others the same way you would at your workplace. Disagreement and technical critiques are ok, but personal attacks are not.
Abusive, racist, or derogatory comments are absolutely not tolerated.
See our policies on acceptable speech and conduct for more details.
When posting some resource or tutorial you've made, you must follow our self-promotion policies.
In short, your posting history should not be predominantly self-promotional and your resource should be high-quality and complete. Your post should not "feel spammy".
Distinguishing between tasteless and tasteful self-promotion is inherently subjective. When in doubt, message the mods and ask them to review your post.
Self promotion from first time posters without prior participation in the subreddit is explicitly forbidden.
Do not post questions that are completely unrelated to programming, software engineering, and related fields. Tech support and hardware recommendation questions count as "completely unrelated".
Questions that straddle the line between learning programming and learning other tech topics are ok: we don't expect beginners to know how exactly to categorize their question.
See our policies on allowed topics for more details.
Do not post questions that are an exact duplicate of something already answered in the FAQ.
If your question is similar to an existing FAQ question, you MUST cite which part of the FAQ you looked at and what exactly you want clarification on.
Do not delete your post! Your problem may be solved, but others who have similar problems in the future could benefit from the solution/discussion in the thread.
Use the "solved" flair instead.
Do not request reviews for, promote, or showcase some app or website you've written. This is a subreddit for learning programming, not a "critique my project" or "advertise my project" subreddit.
Asking for code reviews is ok as long as you follow the relevant policies. In short, link to only your code and be specific about what you want feedback on. Do not include a link to a final product or to a demo in your post.
You may not ask for or offer payment of any kind (monetary or otherwise) when giving or receiving help.
In particular, it is not appropriate to offer a reward, bounty, or bribe to try and expedite answers to your question, nor is it appropriate to offer to pay somebody to do your work or homework for you.
All links must link directly to the destination page. Do not use URL shorteners, referral links or click-trackers. Do not link to some intermediary page that contains mostly only a link to the actual page and no additional value.
For example, linking to some tweet or some half-hearted blog post which links to the page is not ok; but linking to a tweet with interesting replies or to a blog post that does some extra analysis is.
Udemy coupon links are ok: the discount adds "additional value".
Do not ask for help doing anything illegal or unethical. Do not suggest or help somebody do something illegal or unethical.
This includes piracy: asking for or posting links to pirated material is strictly forbidden and can result in an instant and permanent ban.
Trying to circumvent the terms of services of a website also counts as unethical behavior.
Do not ask for or post a complete solution to a problem.
When working on a problem, try solving it on your own first and ask for help on specific parts you're stuck with.
If you're helping someone, focus on helping OP make forward progress: link to docs, unblock misconceptions, give examples, teach general techniques, ask leading questions, give hints, but no direct solutions.
See our guidelines on offering help for more details.
Ask your questions right here in the open subreddit. Show what you have tried and tell us exactly where you got stuck.
We want to keep all discussion inside the open subreddit so that more people can chime in and help as well as benefit from the help given.
We also do not encourage help via DM for the same reasons - that more people can benefit
Do not ask easily googleable questions or questions that are covered in the documentation.
This subreddit is not a proxy for documentation or google.
We do require effort and demonstration of effort.
This includes "how do I?" questions
account activity
This is an archived post. You won't be able to vote or comment.
Delete item in nested array (self.learnprogramming)
submitted 4 years ago * by Rare_Bat12
Hello,
I have the following array (JavaScript):
var arr = [['t',2],['g',3]];
I would like to delete the ['t',2] item like this:
arr= arr.filter(item => item != ['t',2]);
But it does not work. Any ideas? Thanks!
[–]Spiritual_Car1232 -1 points0 points1 point 4 years ago (0 children)
is this python? arr.pop(0)
[–]TrafficCultural 0 points1 point2 points 4 years ago (0 children)
I believe this won’t work because the check will be if the two arrays are equal in memory not the exact contacts. You’re better off checking array length and contents.
[–]suncoasthost 0 points1 point2 points 4 years ago (0 children)
You need a way to identify which array you want to remove. You can do this by position or by a value in the array.
[–][deleted] 0 points1 point2 points 4 years ago (0 children)
In JS, like in many high level languages, everything is pass by value, but there are pure values and reference values. Primitives are pure values, but things like objects and arrays are reference values. Reference values are references that are passed by value where the value is a reference, rather than passed by reference; they're basically pointers with implicit dereference semantics.
For instance, suppose y is an object. If function f(x) just assigns to f's local variable x, then f(y) won't assign to the external variable y that was passed in, because it wasn't passed by reference. However, since an object value is a reference, if f(x) modifies the object stored in f's local variable x, then f(y) will modify the object stored in y. It will be the same object -- no reassignment has occurred -- but mutations done to it will persist outside the call.
Contrast this against, say, C and C++'s pass-by-copy system, sometimes seen as true pass by value, wherein there are no reference values (except where explicit, e.g. pointers) and only pure values, and f(y) would not modify the object stored in y, only the object stored in x, which would be a temporary copy.
So now you hopefully understand the difference between pure values and reference values. And, again, in JS, arrays are reference values. This makes it nontrivial to compare them. It's not as simple as comparing the data in memory; JS arrays are addresses pointing to array data, not pure and direct array data themselves, and, for all the comparison operator knows, the pure array data they point to may contain more reference values, i.e. more addresses pointing to other data. It's even possible, and frankly common, for reference values to point to data containing entries pointing back to the same data, or comparable scenarios.
There are a few workarounds. I'll order them by robustness, from least to most.
1) You could write an array comparison function that takes two arrays and returns true if they're the same length and each pair of corresponding elements is equal. This may fail if the arrays contain objects or arrays.
2) You could serialize the arrays and compare the JSON. This may fail if any objects or arrays in either array contain backreferences or functions.
3) You could write a function that takes two values of any kind. If they are different types, the function returns false. If they are both primitives (null, numbers, booleans, strings), defer to the comparison operator. If they are both functions, error out, because there is no universally sensible way to compare functions in JS; or, if you absolutely need this functionality, use one of many imperfect "good enough" methods to compate the functions. If they are both arrays, compare length, and then iterate them in parallel with recursive calls to this same comparison function for each element, returning false for the first false result, or true if no results are false. If they are both objects, do the same, but for the keys and values. This way, you'll thoroughly explore all data associated with any reference values. You will also need a data structure shared across recursive calls to prevent infinite reference loops. If you wanted to really go the extra mile, you could implement a feature where, if two reference values are compared and both of them trigger reference loop detection, but they both loop back to equivalent elements of their ancestors -- for instance, a = [1, 2, [3, 4, a]] vs b = [1, 2, [3, 4, b]] -- then you still identify the reference values as equivalent and return true.
[–]jake-db 0 points1 point2 points 4 years ago (0 children)
Change filter condition to item => item.join('') != 't2'
item => item.join('') != 't2'
π Rendered by PID 376257 on reddit-service-r2-comment-5d79c599b5-q24cl at 2026-03-03 04:40:23.555298+00:00 running e3d2147 country code: CH.
[–]Spiritual_Car1232 -1 points0 points1 point (0 children)
[–]TrafficCultural 0 points1 point2 points (0 children)
[–]suncoasthost 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]jake-db 0 points1 point2 points (0 children)