I would like to delete all invalid URLs of an array. (e.g. v.1.1, version1.2.00, the.area.0a)
var myArray:Array = new Array("v.1.1", "example.com", "www.example.com","http://example.com","version1.2.00","http://www.example.com","the.area.0a","http://example.com/helloworld123");
How to do that?
I think there are 2 parts of the problem. One is that you want to filter your array. It would create a new array, but you can assign the return from filter back to myArray. The function that you pass to filter function can use String.match to match whatever type of regular expression you deem fit for a valid url (this matching is the second part of the problem).
Related
I have an array variable "Names" with this values for example ["Unity","Block","PRD","Monit"] and want to get each of them value into a new variable.
The output desired would be something like:
Variable Group = Unity
Variabel Test = Block
(...)
As this is an array i thought a basic Names[0] would give me the first value and so on for 1,2,3,etc, but on a logic app I can't figure out how that works.
Is this possible?
Thanks
You do know select value from an array have to specific the index, just don't know how to use variable expression.
Use variables('variable_name') get the variable value and then add the parameter [index] behind it to select the value you want. Just like the below picture shows.
I'm trying to create a page type hierarchy where I can use it both a page hierarchy as well as props and evars, using the page URL. In a nutshell my URL would look something like this:
http://www.domain.com/BrandHomePage/SuperCategory/ProductCategory/Product
The mindset is to take the URL and use a data element to split the URL, and then capture the values into separate data elements that could also be used in a page hierarchy.
var url = "http://www.domain.com/part1/part2/part3/part4"
var parts = url.split('/').splice(2);
console.log(parts);
var baseUrl = parts[0];
var part1 = parts[1];
var part2 = parts[2];
var part3 = parts[3];
var part4 = parts[4]
My question is, would it even be possible to capture each individual portion of the URL into separate data elements? Or is my approach overkill.
Create a Data Element
The following will create a Data Element that returns an array containing up to 4 elements, depending on how many dir levels there are in the URL.
Go to Rules > Data Elements > Create New Data Element
Name it "hier1" (no quotes).
Choose Type Custom Script and click Open Editor.
Add the following code to the code box:
return location.pathname.split('/').filter(Boolean).slice(0,4);
When you are done, Save Changes.
Populate the Hierarchy Variable
Here is an example of populating hier1 on page view.
Go to Overview > Adobe Analytics Tool Config > Pageviews & Content
Under Hierarchy, select Hierarchy1 from the dropdown (this is shown by default).
To the right of the dropdown, in the first field, add %hier1%
Leave the other 3 fields blank.
Leave Delimiter as default comma , (it doesn't matter what you put here).
Note: DTM stringifies the returned array (String(Array) or Array.toString()) from the Data Element, which is effectively the same as doing Array.join(','). This is why the above shows to only put the Data Element reference in the first field, and the Delimiter is ignored.
If your implementation uses a delimiter other than a comma, see additional notes below.
Additional Notes
Populating other Variables
You can also reference %hier1% to populate other variable fields in the Global Variables section. Note that the data element will be stringified with default comma delimiter.
Alternatively, you may consider using Dynamic Variable syntax (e.g. D=h1) as the value, to shorten the request URL. If you are using the latest AppMeasurement and Marketing Cloud Service libraries, this isn't a big deal (the libs will automatically use a POST request instead of GET request if the request URL is too long).
Using the Data Element in Custom Code Boxes
You can use _satellite.getVar('hier1') to return the data element. Note that this returns an array, e.g. ['foo','bar'], so you need to use .join() to concatenate to a single delimited string value.
Using a different Delimiter
If your implementation uses a delimiter other than a comma (,) and you use the same alternate delimiter for all your variables, you can update the Data Element as such:
return location.pathname.split('/').filter(Boolean).slice(0,4).join('[d]');
Where [d] is replaced by your delimiter. Note that this will now cause the Data Element to return a single concatenated String value instead of an Array. Using %hier1% syntax in DTM fields remains the same, but you will no longer need to use .join() in Custom Code boxes.
If your implementation uses different delimiters for different variables, implement the Data Element per the original instructions in the first section. You may use %hier1% syntax in DTM fields only if the delimiter is a comma. For all other delimiters, you will need to populate the variable in a custom code box and use a .join('[d]').
Capturing more than Four Directory Levels
Since you are no longer trying to put a value in four hierarchy fields, you may consider pushing more levels to hier1 or other variables.
In the Data Element, change the 4 in .slice(0,4); to whatever max level of dirs you want to capture. Or, if you want to capture all dir levels, remove .slice(0,4) completely.
I use to use the where method from the Collections in backbone. But I don't see how to fetch this result:
MyCollection.Group[x].id
As you can guess, MyCollection is the collection, Group is an array, and id is the field I would like to match for a specific value, something like:
MyCollection.findWhere(Group[x].id: 34);
I have seen the "contains" function of underscore but it doesn't seems to work with associative arrays
Is there a way to do it or should we parse the collection manually using Javascript ?
Collection.where and Collection.findWhere are convenience functions for simple filters. In your case, you would use the more complex Collection.find (proxied to _.find)
find _.find(list, iterator, [context])
Looks through each value in the list, returning the first one that passes a truth test
(iterator). The function returns as soon as it finds an acceptable
element, and doesn't traverse the entire list.
And if I understand correctly your condition, it could look like
MyCollection.find(function(model) {
return _.findWhere(model.get('Group'), {id: 34});
})
you can choose to use jQuery .find() . see examples here: http://api.jquery.com/find/
I know that the standard method for passing named parameters in a get request, is:
?paramName=value&anotherParam=anotherValue...
In my case, I want to pass an array of parameters
However, I want to pass multiple parameters with the same meaning - an array.
In js that would be
var users = ['bob', 'sam', 'bill'];
and I want to pass the users array via get.
What would be the way to accomplish this?
You will need to serialize them into some form of string that can be re-parsed into an array.
For, example, you could use...
?param[]=a¶m[]=b¶m[]=c
...or something like...
?params=[a][b][b].
Are there options for converting an Array to a Vector in ActionScript without iterating the array?
What about the other way (converting a Vector to an Array)?
For the Array to Vector, use the Vector.<TYPE>() function that accept an array and will return the vector created :
var aObjects:Array = [{a:'1'}, {b:'2'}, {c:'3'}];
// use Vector function
var vObjects:Vector.<Object> = Vector.<Object>(aObjects);
For the other there is no builtin function, so you have to do a loop over each Vector item and put then into an Array
vObjects.push.apply(null, aObjects);
And another way to do it.
The trick here is simple. If you try to use the concat() method to load your array into a vector it will fail because the input is a vector and instead of adding the vector elements AS will add the whole vector as one entry. And if you were to use push() you'd have to go through all items in the array and add them one by one.
In ActionScript every function can be called in three ways:
Normal way: vObjects.push(aObjects)
Throws error because aObjects is not an Object but an Array.
The call method: vObjects.push.call(this, myObject1, myObject2, ..., myObjectN)
Doesn't help us because we cannot split the aObjects array into a comma-separated list that we can pass to the function.
The apply method: vObjects.push.apply(this, aObjects)
Going this route AS will happily accept the array as input and add its elements to the vector. You will still get a runtime error if the element types of the array and the vector do not match. Note the first parameter: it defines what is scoped to this when running the function, in most cases null will be fine, but if you use the this keyword in the function to call you should pass something other than null.
var myArray:Array = [].concat(myVector);
might work.