|
4 | 4 | * JsArray Javascript array utilities This class is part of springBoot-VueJS
|
5 | 5 | *
|
6 | 6 | * @author jcheron myaddressmail@gmail.com
|
7 |
| - * @version 1.0.3 |
| 7 | + * @version 1.0.4 |
8 | 8 | *
|
9 | 9 | */
|
10 | 10 | public class JsArray {
|
@@ -75,4 +75,28 @@ public static String addAll(String array,String elements) {
|
75 | 75 | public static String removeByProperty(String array,String property,String value) {
|
76 | 76 | return array+".splice("+array+".findIndex(e => e."+property+"=="+value+"),1);";
|
77 | 77 | }
|
| 78 | + |
| 79 | + public static String findByProperty(String array,String property,String value) { |
| 80 | + return array+".find(e => e."+property+"=="+value+");"; |
| 81 | + } |
| 82 | + |
| 83 | + public static String findIndexByProperty(String array,String property,String value) { |
| 84 | + return array+".findIndex(e => e."+property+"=="+value+");"; |
| 85 | + } |
| 86 | + |
| 87 | + public static String containsByProperty(String array,String property,String value) { |
| 88 | + return array+".findIndex(e => e."+property+"=="+value+")>-1;"; |
| 89 | + } |
| 90 | + |
| 91 | + public static String contains(String array,String element) { |
| 92 | + return array+".indexOf("+element+")>-1;"; |
| 93 | + } |
| 94 | + |
| 95 | + public static String letFindByProperty(String variable,String array,String property,String value) { |
| 96 | + return "let "+variable+"="+findByProperty(array,property,value); |
| 97 | + } |
| 98 | + |
| 99 | + public static String letRemoveByProperty(String variable,String array,String property,String value) { |
| 100 | + return "let "+variable+"="+removeByProperty(array,property,value); |
| 101 | + } |
78 | 102 | }
|
0 commit comments