Tag: arrays

Output a PDF in PHP from a byte array

I am getting a byte array from a WCF service that generated the PDF and converted it to a byte array. I need to able to get the byte array and using either PHP or Javascript (or jQuery) take that byte array and convert it back to a downloadable PDF. I would prefer a solution […]

Finding an item of an array of numbers without using a loop

This is a stupid question, it feels like one. But mental block is bad right now. 🙁 My problem is I have an array consisting only of numbers. I want to use that array as a lookup, but the number I pass to lookup a number in the array keeps looking to the array in […]

Find if an element exists in Javascript array

I am trying to find if an element exists in Array with a name. Couldn’t figure out, how to achieve the same let string = [{“plugin”:[“”]}, {“test”: “123”}] console.log(string); console.log(string instanceof Array); //true console.log(“plugin” in string); //false

How to group array of objects by key

does anyone know of a lodash way to group an array of objects by an object key then create a new array of objects based on the grouping? For example, I have an array of car objects: var cars = [ { ‘make’: ‘audi’, ‘model: ‘r8’, ‘year’: ‘2012’ }, { ‘make’: ‘audi’, ‘model: ‘rs5’, ‘year’: […]

Join sequence of arrays with array delimeters (“intersperse”)

Is there a function that lets me concat several arrays, with delimiters between them (the delimiters are also arrays), similarly to how join works but not restricted to strings? The function can be standard JS or part of a major library such as lodash (which is why it’s referenced in the tags). Here is an […]

How to get subset of two arrays in javascript?

What I am trying to do is if I have Array a = {1,2,3,4}; b = {1,2}; Then I want subset array as c = {3,4}; Can anybody help me?

Number formatting in JavaScript

I am trying to create a JS script to format numbers using , separator but something is going bad in the logic implementation. I am changing values of arr1 here. This is the JS code I am using this time – <script> var arr1 = [1,2,3,4,5,6,7]; arr1.reverse(); var i = 1; var tempArr = new […]

Count the number of true members in an array of boolean values

New to javascript and I’m having trouble counting the number of trues in an array of boolean values. I’m trying to use the reduce() function. Can someone tell me what I’m doing wrong? //trying to count the number of true in an array myCount = [false,false,true,false,true].reduce(function(a,b){ return b?a++:a; },0); alert(“myCount =”+ myCount); // this is […]

Iterate over a collection of objects in javascript and return true from that function

I have an object called collection, and I want to test to see if justin is part of this collection. collection = { 0:{screen_name:”justin”},1:{screen_name:”barry”}} I’m trying to discover the most efficient method, to pass in a name to function called present_user(user), to see if the user is part of the collection and I’m kind of […]

How to check if an array contains another array?

I needed 2d arrays, so I made nested array since JavaScript doesn’t allow them. They look like that: var myArray = [ [1, 0], [1, 1], [1, 3], [2, 4] ] How can I check if this array includes a specific element (i.e. one of these [0,1] arrays) in vanilla JS? Here is what I […]