Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Verify values
- (function(prop){
- var vL = dataLayer[0].lists[0].vehicles, validOptions = [ "dealer", "private" ], verdict, exceptions = 0;
- for ( i = 0; i < vL.length; i++ ){
- console.log( vL[ i ][ prop ] );
- if ( validOptions.indexOf( vL[ i ][ prop ] ) === -1 ){ exceptions += 1;}
- }
- verdict = exceptions > 0 ? exceptions + " invalid values" : "All good";
- console.log( verdict );
- })("adType");
- // Three properties at once:
- (function(property1,property2, property3) {
- for (var index = 0; index < dataLayer.length; index++) {
- if (dataLayer[index].lists != undefined) {
- var theList = dataLayer[index].lists[0].vehicles;
- for (var i = 0; i < theList.length; i++) {
- var theVehicle = theList[i];
- console.log(property1 + ": " + theVehicle[property1] + ", " + property2 + ": " + theVehicle[property2] + ", " + property3 + ": " + theVehicle[property3] ); // …print out the values
- }
- }
- }
- })("adType","condition", "province");
- // Neatified output:
- (function(property1, property2, property3) {
- if (dataLayer[0].lists != undefined) {
- var theList = dataLayer[0].lists[0].vehicles;
- for (var i = 0; i < theList.length; i++) {
- var theVehicle = theList[i];
- console.log("===== " + theVehicle.make + " " + theVehicle.model + " =====");
- for (a = 0; a < arguments.length; a++) {
- console.log(arguments[a] + " = " + theVehicle[arguments[a]]);
- }
- }
- }
- })("adType", "condition", "province");
- // v4: Use any number of arguments:
- (function(){
- if (dataLayer[0].lists != undefined) {
- var theList = dataLayer[0].lists[0].vehicles;
- for (var i = 0; i < theList.length; i++) {
- var theVehicle = theList[i];
- console.log("==== " + theVehicle.make + " " + theVehicle.model + " ====");
- for (a = 0; a < arguments.length; a++) {
- console.log(arguments[a] + " = " + theVehicle[arguments[a]]);
- }
- }
- }
- })("adType", "condition", "province", "financingPrice");
- // v5: we don't know where our list is
- (function(){
- for(var m=0; m<dataLayer.length; m++){
- if (dataLayer[m].lists != undefined){
- for(var n=0; n<dataLayer[m].lists.length; n++){
- var theList = dataLayer[m].lists[n].vehicles;
- for (var i=0; i<theList.length; i++){
- var theVehicle = theList[i];
- console.log(i + ("@").repeat(30));
- console.log(theVehicle.make + " " + theVehicle.model);
- for (var a=0; a<arguments.length; a++) {
- console.log(arguments[a] + " = " + theVehicle[arguments[a]]);
- }
- }
- }
- }
- }
- })("adType", "condition", "province", "financingPrice");
Advertisement
Add Comment
Please, Sign In to add comment