- In your
package.json
file add a host and port to your webpack dev server script using the following flags:
"dev:serve": "webpack-dev-server -d --config ./webpack.config.js --host 0.0.0.0 --port 8080"
-
Next run your dev server command:
$ npm run dev:serve
-
In a new terminal tab type the following command:
$ ifconfig | grep inet
-
Copy the following 4 numbers after
inet
from what gets printed in your terminal (this is your IP address for yourlocalhost
): -
Next go to a web browser on your mobile device (make sure you are on the same network as your dev server). Replace where you would usually type
localhost
with the 4 numbers from your terminal:
http://localhost:8080/
http://10.166.136.78:8080/
Usually you would check the User agent string but this can be unreliable because it can be spoofed easily. A more reliable way to detect their browser is to check whether it has features specific to that platform:
// Opera 8.0+
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';
// At least Safari 3+: "[object HTMLElementConstructor]"
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;
// Edge 20+
var isEdge = !isIE && !!window.StyleMedia;
// Chrome 1+
var isChrome = !!window.chrome && !!window.chrome.webstore;
// Blink engine detection
var isBlink = (isChrome || isOpera) && !!window.CSS;
Naive solution:
var arr1 = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
var arr2 = [{id: 2}, {id: 4}, {id: 6}, {id: 8}];
var idArray1 = [];
var idArray2 = [];
var uniqueArray = arr2.filter(function(obj, index) {
idArray1.push(arr1[index].id);
idArray2.push(obj.id);
var uniqueIdArray = idArray2.filter(function(obj2) {
return idArray1.indexOf(obj2) === -1;
});
return uniqueIdArray.indexOf(obj.id);
});
console.log(uniqueArray); // [{id: 6},{id: 8}]
Had to flatten one of the object arrays into an array of pure values which could then be verified against the array that we want to filter.
Refactored solution:
var arr3 = arr1.map(function(item) {
return item.id;
});
var uniqueArray = arr2.filter(function(obj, index) {
return arr3.indexOf(obj.id) === -1;
});
console.log(uniqueArray); // [{id: 6},{id: 8}]